1

I am trying to hit a nginx server that is behind an alb. I am triggering a simple HTTP2 POST request using pycurl. My request looks like this'

import io
import pycurl
curl = pycurl.Curl()
curl.setopt(curl.URL, "https://alb-xxxx.us-east-1.elb.amazonaws.com/endpoint")
curl.setopt(pycurl.HTTP_VERSION, pycurl.CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE)
curl.setopt(pycurl.POST, 1)
curl.setopt(pycurl.VERBOSE, 1)
curl.setopt(pycurl.SSL_VERIFYPEER, 0)
curl.setopt(pycurl.SSL_VERIFYHOST, 0)

with io.BytesIO() as buf:
    curl.setopt(curl.WRITEFUNCTION, buf.write)
    curl.perform()
    print(buf.getvalue())
    curl.close()

The error i am getting is

error                                     Traceback (most recent call last)
<ipython-input-91-0756005b6c1b> in <module>()
     16 with io.BytesIO() as buf:
     17     curl.setopt(curl.WRITEFUNCTION, buf.write)
---> 18     curl.perform()
     19     print(buf.getvalue())
     20     curl.close()

error: (92, 'HTTP/2 stream 1 was not closed cleanly: INTERNAL_ERROR (err 2)')

the error occurrence is random. some times I get correct response and sometimes I get error like this. But when I try to do the same in curl I am getting correct response always. This is my curl command.

curl -v -k --http2-prior-knowledge -X POST https://alb-xxx.us-east-1.elb.amazonaws.com/endpoint

My post request response is a string({"field":"value"}). My NGINX configuration file looks like this

        location =/endpoint {
        if ($request_method = POST) {
        return 200 '{"field":"value"}';
}
}

I don't know why I am getting correct response in curl but getting a different response in pycurl. Am I doing anything wrong in pycurl ?

Pycurl version -> 7.43.0.6 Python version -> 3.8.5

Thanks. Any help is appreciated.

learner
  • 117
  • 2
  • 10
  • Seems like this will be handy: https://stackoverflow.com/questions/56413290/getting-curl-92-http-2-stream-1-was-not-closed-cleanly-internal-error-err – BcK Mar 14 '21 at 22:32

0 Answers0