Posts

Showing posts with the label Rest

AttributeError: 'str' Object Has No Attribute 'items'

Answer : You are passing in a string ; headers can't ever be a JSON encoded string, it is always a Python dictionary. The print results are deceptive; JSON encoded objects look a lot like Python dictionary representations but they are far from the same thing. The requests API clearly states that headers must be a dictionary: headers – (optional) Dictionary of HTTP Headers to send with the Request . JSON data is something you'd send as content to another server, not something you'd use to communicate with a Python API. I had this issue and I needed to make the header with a content type and pass in a data element as json. import requests import json headerInfo = {'content-type': 'application/json' } payload = {'text': 'okay!!!', 'auth_token': 'aasdasdasdasd'} jLoad = json.dumps(payload) r = requests.post('http://example.com:3030/widgets/init', headers=headerInfo, data=jLoad) print r.text...

Bulk POST/PUT API Requests Using POSTMAN Or Any Other Means

Image
Answer : Never mind I figured out a way to use postman's collection runner to accomplish the same. For those who struggled like the way I did, here is how to use that feature and its even easier to substitute values to your url on the go. First create a request in Postman: Below is a screenshot for Example : Now the requirement is to post the below url: https://someApiPOSTRequest/clientAssign?auth=123|asdf&otherParamsList=123Params&someOtherParams={{VariableFromFile}}&additionalParams=hardcodedOnURL with values being substituted for {{VariableFromFile}} from the csv file you will need to upload. Your csv should be formatted as below, where the header should have the same variable name used on your url: Click on the '>' button shown below beside Example folder and click on 'Run' to open the same on Collection runner window of postman: Once the Collection Runner window opens up, click on select file option to upload your csv ...

Body Of Http.DELETE Request In Angular2

Answer : The http.delete(url, options) does accept a body. You just need to put it within the options object. http.delete('/api/something', new RequestOptions({ headers: headers, body: anyObject })) Reference options interface: https://angular.io/api/http/RequestOptions UPDATE : The above snippet only works for Angular 2.x, 4.x and 5.x. For versions 6.x onwards, Angular offers 15 different overloads. Check all overloads here: https://angular.io/api/common/http/HttpClient#delete Usage sample: const options = { headers: new HttpHeaders({ 'Content-Type': 'application/json', }), body: { id: 1, name: 'test', }, }; this.httpClient .delete('http://localhost:8080/something', options) .subscribe((s) => { console.log(s); }); You are actually able to fool Angular2 HTTP into sending a body with a DELETE by using the request method. This is how: let body = { target: targetId, subset: "frui...