How to properly use python requests post for sending data? or What's the best way to handle a python

16 Replies, 1993 Views

Ugh, python requests post issues are the bane of my existence.

Try this:
```python
import requests
from requests.exceptions import RequestException

try:
response = requests.post(url, json=data, timeout=10)
response.raise_for_status() # This’ll throw an error for 4xx/5xx
except RequestException as e:
print(f"Oops: {e}")
```

This’ll give you a clearer error. Also, maybe the API expects form-data? Swap `json=data` for `data=data`.

Messages In This Thread



Users browsing this thread: 1 Guest(s)