How to set GET parameters using PyCurl?

I am trying to make a GET request for a REST api using PycURL. I can successfully make a request if I do not pass any parameters. I can also make a POST request by doing the following:

curl.setopt (pycurl.POSTFIELDS, post_data)

I want to make a receive request that includes login options. If I try to use the above line to pass parameters, it will try to make POST. I cannot figure out how to set the login parameters and make a GET request.

Any help would be appreciated.

+4
source share
2 answers

Like a normal browser URL, are GET parameters encoded and added after ? to the url. Using python urllib.urlencode you can do:

 import urllib import pycurl url = 'http://www.google.com/search' params = {'q': 'stackoverflow answers'} c = pycurl.Curl() c.setopt(c.URL, url + '?' + urllib.urlencode(params)) ... # and so on and so forth ... 
+11
source

There seems to be no pycurl.GETFIELDS parameter, so you have to pass these parameters in the url, for example:

 http://your_url/some_path?param1=value1&param2=value2 

where you should replace param1, param2, value1 and value2 with what values โ€‹โ€‹you saved in post_data .

+1
source

Source: https://habr.com/ru/post/1344199/


All Articles