A more proper way of doing this with requests
would be:
import requests
payload = {'username': 'bob', 'email': '[email protected]'}
try:
response = requests.put(url="http://somedomain.org/endpoint", data=payload)
response.raise_for_status()
except requests.exceptions.RequestException as e:
print(e)
raise
This raises an exception if there is an error in the HTTP PUT request.