Skip to content
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

HTTP/2 stream not closed cleanly #79

Closed
mavic111 opened this issue Jul 11, 2023 · 3 comments
Closed

HTTP/2 stream not closed cleanly #79

mavic111 opened this issue Jul 11, 2023 · 3 comments

Comments

@mavic111
Copy link

To reproduce error:

from curl_cffi import requests

client = requests.Session(impersonate="chrome110")

res = client.get('https://google.com')
print("Google", res.status_code)
res = client.get('https://shopee.co.id')
print("Shopee", res.status_code)
Google 200
Traceback (most recent call last):
  File "C:\Users\muham\source\repos\blegping\venv\Lib\site-packages\curl_cffi\requests\session.py", line 436, in request
    c.perform()
  File "C:\Users\muham\source\repos\blegping\venv\Lib\site-packages\curl_cffi\curl.py", line 191, in perform
    self._check_error(ret, action="perform")
  File "C:\Users\muham\source\repos\blegping\venv\Lib\site-packages\curl_cffi\curl.py", line 84, in _check_error
    raise error
curl_cffi.curl.CurlError: Failed to perform, ErrCode: 92, Reason: 'HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1)'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\muham\source\repos\blegping\main.py", line 7, in <module>
    res = client.get('https://shopee.co.id')
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\muham\source\repos\blegping\venv\Lib\site-packages\curl_cffi\requests\session.py", line 438, in request
    raise RequestsError(e)
curl_cffi.requests.errors.RequestsError: Failed to perform, ErrCode: 92, Reason: 'HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1)'
@yifeikong
Copy link
Owner

yifeikong commented Jul 11, 2023


╰─>$ cat test.py                                               
from curl_cffi import requests

client = requests.Session(impersonate="chrome110")

res = client.get('https://google.com')
print("Google", res.status_code)
res = client.get('https://shopee.co.id')
print("Shopee", res.status_code)

╰─>$ python test.py                                            
Google 200
Shopee 200

Sorry, I can not reproduce this. Network problems are not always reproducible, especially http2 related ones.

This should be resolved if you force libcurl to use http1.1 only. Unfortunately, I did not expose the interface for setting this option easily, which should be fixed in the next minor version. For now, you can add one line here to use http1.1 explicitly.

CURL_HTTP_VERSION_1_1 = 2
c.setopt(CurlOpt.HTTP_VERSION, CURL_HTTP_VERSION_1_1)

@mavic111
Copy link
Author

it works, thanks.

@yifeikong
Copy link
Owner

For v0.5.8 above, use this:

from curl_cffi import requests, CurlHttpVersion

requests.get("https://example.com", http_version=CurlHttpVersion.V1_1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants