-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Streamed uploads fail against local httpbin #33
Comments
This probably belongs as a report against httpbin. |
@jkbrzt does this work against httpbin.org? |
@kevin1024 yes it does work against httpbin.org. The
|
I'm wondering if switching to Gunicorn (#28) would solve it. Will try to play with it a bit. |
Gunicorn solves everything :) |
@kennethreitz I wish! 🦄 After some more debugging it doesn't seem to have anything to do with neither
from __future__ import print_function
import requests
def stream():
yield b'spam'
def test_httpbin_org():
r = requests.post('http://httpbin.org/post', data=stream())
assert r.json()['data'] == 'spam'
def test_local_httpbin():
r = requests.post('http://127.0.0.1:5000/post', data=stream())
assert r.json()['data'] == 'spam'
def test_local_httpbin_gunicorn():
r = requests.post('http://127.0.0.1:8000/post', data=stream())
assert r.json()['data'] == 'spam'
def test_pytest_httpbin(httpbin):
r = requests.post(httpbin.url + '/post', data=stream())
assert r.json()['data'] == 'spam'
if __name__ == '__main__':
for test in [test_httpbin_org, test_local_httpbin, test_local_httpbin_gunicorn]:
print(test.__name__, end=': ')
try:
test()
except AssertionError as e:
print('fail')
else:
print('ok') python -m httpbin.core & # naked httpbin
gunicorn httpbin:app & # httpbin behind gunicorn $ python test.py # outside pytest
test_httpbin_org: ok
test_local_httpbin: fail
test_local_httpbin_gunicorn: fail $ py.test test.py # through pytest
=============================== test session starts ===============================
platform darwin -- Python 3.5.1, pytest-2.9.0, py-1.4.31, pluggy-0.3.1
rootdir: /Users/jakub/Code/OS/pytest-httpbin, inifile:
plugins: httpbin-0.2.2, cov-2.2.1
collected 4 items
test.py .FFF
==================================== FAILURES =====================================
_______________________________ test_local_httpbin ________________________________
def test_local_httpbin():
r = requests.post('http://127.0.0.1:5000/post', data=stream())
> assert r.json()['data'] == 'spam'
E assert '' == 'spam'
E + spam
test.py:13: AssertionError
___________________________ test_local_httpbin_gunicorn ___________________________
def test_local_httpbin_gunicorn():
r = requests.post('http://127.0.0.1:8000/post', data=stream())
> assert r.json()['data'] == 'spam'
E assert '' == 'spam'
E + spam
test.py:17: AssertionError
_______________________________ test_pytest_httpbin _______________________________
httpbin = <Server(<class 'pytest_httpbin.serve.Server'>, started 123145309245440)>
def test_pytest_httpbin(httpbin):
r = requests.post(httpbin.url + '/post', data=stream())
> assert r.json()['data'] == 'spam'
E assert '' == 'spam'
E + spam
test.py:21: AssertionError
------------------------------ Captured stderr call -------------------------------
127.0.0.1 - - [08/Mar/2016 18:19:27] "POST /post HTTP/1.1" 200 389
======================= 3 failed, 1 passed in 1.73 seconds ======================== |
The test does not work against httpbin.org now, it will response >>> import requests
>>> requests.__version__
'2.18.4'
>>>
>>> def stream():
... yield b'ham'
... yield b'spam'
...
>>>
>>> r = requests.post('http://httpbin.org/post', data=stream())
>>> r
<Response [411]>
>>> r.reason
'Length Required'
>>> If test against a local gunicorn server, # If the request doesn't specify a content length and there is no max
# length set, returning the stream is potentially dangerous because it
# could be infinite, maliciously or not. If safe_fallback is true, return
# an empty stream for safety instead.
if content_length is None and max_content_length is None:
return safe_fallback and _empty_stream or stream Sometimes it will cause
If add |
Against the local
httpbin
It fails every time and the failuire has two flavours (see bellow).Relevant: https://github.com/kennethreitz/requests/issues/2422
test.py
body missing:
requests.exceptions.ConnectionError: [Errno 32] Broken pipe
:The text was updated successfully, but these errors were encountered: