You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
>>> import httpx
>>> import requests
>>> url = 'http://httpbin.org/anything'
>>> files = {'file': ('report.csv', 'some,data,to,send\nanother,row,to,send\n')}
>>> requests.post(url, files=files)
<Response [200]>
>>> httpx.post(url, files=files)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".../site-packages/httpx/_api.py", line 320, in post
trust_env=trust_env,
File ".../site-packages/httpx/_api.py", line 110, in request
allow_redirects=allow_redirects,
File ".../site-packages/httpx/_client.py", line 785, in request
cookies=cookies,
File ".../site-packages/httpx/_client.py", line 355, in build_request
cookies=cookies,
File ".../site-packages/httpx/_models.py", line 1097, in __init__
headers, stream = encode_request(content, data, files, json)
File ".../site-packages/httpx/_content.py", line 179, in encode_request
return encode_multipart_data(data or {}, files, boundary)
File ".../site-packages/httpx/_content.py", line 124, in encode_multipart_data
multipart = MultipartStream(data=data, files=files, boundary=boundary)
File ".../site-packages/httpx/_multipart.py", line 161, in __init__
self.fields = list(self._iter_fields(data, files))
File ".../site-packages/httpx/_multipart.py", line 175, in _iter_fields
yield FileField(name=name, value=value)
File ".../site-packages/httpx/_multipart.py", line 86, in __init__
raise TypeError(f"Expected bytes or bytes-like object got: {type(fileobj)}")
TypeError: Expected bytes or bytes-like object got: <class 'str'>
From httpx 0.20.0
The raise_for_status() method will now raise an exception for any responses except those with 2xx status codes. Previously only 4xx and 5xx status codes would result in an exception.
>>> import requests
>>> import httpx
>>> url = 'http://github.com'
>>> requests.get(url, allow_redirects=False).raise_for_status()
>>> httpx.get(url, follow_redirects=False).raise_for_status()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".../site-packages/httpx/_models.py", line 1507, in raise_for_status
raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Redirect response '301 Moved Permanently' for url 'http://github.com'
Redirect location: 'https://github.com/'
For more information check: https://httpstatuses.com/301
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Some recent diversions from
requestsis not documented inRequests Compatibility GuideFrom httpx 0.19.0:
From httpx 0.20.0
These might be worth to be noted in https://www.python-httpx.org/compatibility/
Beta Was this translation helpful? Give feedback.
All reactions