Menu
You would instead do curl.setopt(pycurl.URL, '.' I have user name and password for my site. I need to login the site using username and password using Pycurl. Then I need to send the request to. want to convert this using Pycurl code so that it will be easy to parse the xml from Python. Do as Daniel suggests to get the. Convert Curl commands to Python requests with ReqBin Online Curl client. The Curl Converter uses the Python Requests Library for the generated code. Test your Curl commands online with the ReqBin Curl Client and convert them to Python code when ready. Curl Converter automatically generates requests library calls for HTTP headers and JSON content. The Curl Converter uses the vanilla JavaScript XMLHttpRequest calls for the generated code. Test your Curl commands online with the ReqBin Curl Client and convert them to JavaScript code when ready. Curl Converter automatically generates AJAX calls for HTTP headers and JSON content. The Python code was automatically generated for the Convert. I want to use the 'requests' library in python to make a POST request. But the api I'm trying to use, uses curl to make the request and I don't know how to convert that. This is the curl command.
- Convert Curl Command To Python
- Run Curl In Python
- Convert Curl To Python Request
- Convert Curl To Python Urllib2
cURL / Mailing Lists / curl-and-python / Single Mail
- This message:[ Message body ] [ More options ]
- Related messages:[ Next message ][ Previous message ][ In reply to ]
Date: Sun, 19 Dec 2010 21:34:21 +0200
Hi
On 19 December 2010 18:50, Mohan L <l.mohanphy_at_gmail.com> wrote:
>
> Dear All,
>
> I am new to Pycurl. I am unable to find good doc in the internet to start it
> myself. I need some one help to getting start Pycurl.
>
> Dear All,
>
> I am new to Pycurl. I am unable to find good doc in the internet to start it
> myself. I need some one help to getting start Pycurl.
It's pretty similar to using it in C. Just check the documentation on
the pycurl web site and also use the curl documentation. In
particular
http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
the pycurl web site and also use the curl documentation. In
particular
http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
Where you might do curl_easy_setopt(curl, CURLOPT_URL, '...'); in C,
you would instead do curl.setopt(pycurl.URL, '...') in Python.
you would instead do curl.setopt(pycurl.URL, '...') in Python.
> I have user name and password for my site. I need to login the site using
> username and password using Pycurl. Then I need to send the request to
> server and the server will send the xml file as response. I am doing this
> like this in Curl. I am sending the username and password in in one curl
> call, it return 'JSESSIONID' id. I am using the session id in the below
> command to fetch the xml data from server.
>
> curl -d 'command=listCapacity&zoneId=1&podId=1' -X POST -b
> 'JSESSIONID=webD~C' https://manage.com:443/client/api -k > out.xml
>
> running the above command in command line gives the xml file as output. I
> want to convert this using Pycurl code so that it will be easy to parse the
> xml from Python.
> username and password using Pycurl. Then I need to send the request to
> server and the server will send the xml file as response. I am doing this
> like this in Curl. I am sending the username and password in in one curl
> call, it return 'JSESSIONID' id. I am using the session id in the below
> command to fetch the xml data from server.
>
> curl -d 'command=listCapacity&zoneId=1&podId=1' -X POST -b
> 'JSESSIONID=webD~C' https://manage.com:443/client/api -k > out.xml
>
> running the above command in command line gives the xml file as output. I
> want to convert this using Pycurl code so that it will be easy to parse the
> xml from Python.
Do as Daniel suggests to get the C code, and work from there. I have
pasted some Python code which should do the same as your curl command
as a place to start.
pasted some Python code which should do the same as your curl command
as a place to start.
> I need some code clue to achieve the above. Any help will be really
> appreciated. I could be very nice some code and explanation of the code, so
> that I will try to learn myself further.
> appreciated. I could be very nice some code and explanation of the code, so
> that I will try to learn myself further.
The code is so simple it should not need any explanation.
> Thanks For Your Time.
#!/usr/bin/env python
Convert Curl Command To Python
import pycurl
def main():
curl = pycurl.Curl()
if not curl:
print 'Could not create Curl handle'
return
curl = pycurl.Curl()
if not curl:
print 'Could not create Curl handle'
return
curl.setopt(pycurl.URL, 'https://manage.com/client/api')
curl.setopt(pycurl.NOPROGRESS, True)
curl.setopt(pycurl.POSTFIELDS, 'command=listCapacity&zoneId=1&podId=1')
curl.setopt(pycurl.USERAGENT, '...')
curl.setopt(pycurl.COOKIE, 'JSESSIONID=webD~C')
curl.setopt(pycurl.SSL_VERIFYPEER, False)
curl.setopt(pycurl.NOPROGRESS, True)
curl.setopt(pycurl.POSTFIELDS, 'command=listCapacity&zoneId=1&podId=1')
curl.setopt(pycurl.USERAGENT, '...')
curl.setopt(pycurl.COOKIE, 'JSESSIONID=webD~C')
curl.setopt(pycurl.SSL_VERIFYPEER, False)
curl.perform()
Run Curl In Python
if __name__ '__main__':
main()
main()
But, the above is not ideal, because how do you generate the POSTFIELDS string?
It's better to do this:
postfields = [('command', 'listCapacity'), ('zoneId', '1'), ('podId', '1')]
curl.setopt(pycurl.HTTPPOST, postfields)
curl.setopt(pycurl.HTTPPOST, postfields)
Convert Curl To Python Request
Or something like that anyway...
Received on 2010-12-19
- This message: [ Message body ]
- Next message: Mohan L: 'Check return value of curl.perform()'
- Previous message: Daniel Stenberg: 'Re: help to Converting Curl to PyCurl code'
- In reply to: Mohan L: 'help to Converting Curl to PyCurl code'
Convert Curl To Python Urllib2
- Contemporary messages sorted: [ by date ] [ by thread ] [ by subject ] [ by author ] [ by messages with attachments ]