How to properly use requests post in Python for API calls? or What's the best way to handle a request

12 Replies, 887 Views

Yo, had the same issue last week! Turns out some servers reject requests without a user-agent. Try adding:

```python
headers = {'User-Agent': 'my-app/1.0'}
```

Also, dump the response with `print(response.text)`—might give you a clue why the server’s ignoring you.

For retries, I just use a dumb loop with `try/except`. Not elegant but works.

Btw, Postman’s great for testing API calls before coding them in requests post python.

Messages In This Thread



Users browsing this thread: 1 Guest(s)