question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Post Request ok with postman but failed using code in python

See original GitHub issue

Hi everybody,

I’m trying to write a little python code to get a json list from an website Api.

with postman i use the url and the two needed params and the result is good (as you can see in postman picture. postman

After this i take postman to generate the python Code related to this query, the result is like this

import requests

url = "https://ww5.files-seekr.com/api/search/all"

payload = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"query\"\r\n\r\nbatman\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"api_key\"\r\n\r\n1305ca510f59d2d1\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--"
headers = {
    'content-type': "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
    'cache-control': "no-cache",
    'postman-token': "eae0d2e2-be2b-b95b-aebd-15226e17eed4"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)

And using python Gui, the result is not ok (error 405)

Python

i’ve tried using different syntax of the python code with no success (this following is one of them)

import requests

url = "https://ww5.files-seekr.com/api/search/all"

payload = {'api_key': '1305ca510f59d2d1', 'query': 'batman'}

response = requests.post(url=url, data=payload)

print(response.text)

Can someone give me a little help ?

Thanks a lot.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:29

github_iconTop GitHub Comments

13reactions
anton-botcommented, May 5, 2020

Wait. Which Python? This is a JavaScript library.

12reactions
jondoesntgitcommented, Apr 28, 2020

Thanks @GSManganneau.

This did not work

data = {'foo': {'bar': 'baz'}}
requests.put(url, header=header, data=data)

But this did

import json
data = {'foo': {'bar': 'baz'}}
requests.put(url, header=header, data=json.dumps(data))

That’s in Python 2.7, Requests 2.23.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

POST request works in Postman but not in Python
When I do it in Python 2.7 (using a Jupyter notebook), I get the error "No JSON object could be decoded". What am...
Read more >
Not getting any output using python, but using Postman i am ...
Using POSTMAN, first i used POST to get the session ID, second GET to get the output response. In POSTMAN,. 1) POST: import...
Read more >
Post requests works on postman but not on python3 - Help
I sent a post requests using postman in this URL: my form-data was: u: ... But the automated python code is not working...
Read more >
Post Method works for Postman but Python - Infoblox Community
I coud achieve post requests via Postman when i try in python code which gives below error. I read its because of role,...
Read more >
API calls work in Postman but not in Powershell or Python
Im just trying to get a list of finished reports at this point but it doesn't matter what I do, all calls work...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found