Python equivalent of PHP curl request

后端 未结 4 1637
我在风中等你
我在风中等你 2021-01-07 02:38

I\'m using Rauth for my queries to the Beatport API. I\'m using this working example in PHP as reference.

This PHP code below uses a request token to log in and auth

相关标签:
4条回答
  • 2021-01-07 02:40

    You should use urlopen to issue requests.

    A simple example:

    import urllib2
    result = urllib2.urlopen("http://www.google.com/")
    print result.read()
    

    Read more here: http://docs.python.org/2/library/urllib2.html

    Google urlopen code examples, and you will find what you need.

    0 讨论(0)
  • 2021-01-07 02:49

    Why not just use requests? http://www.python-requests.org/en/latest/

    This library should be able to do what this php code is doing easily.

    0 讨论(0)
  • 2021-01-07 02:59

    use pycurl it is a python implementation of lib curl.

    import pycurl
    c = pycurl.Curl()
    c.setopt(pycurl.URL, "http://www.python.org/")
    c.setopt(pycurl.HTTPHEADER, ["Accept:"])
    ...
    

    you can find more examples and documentation here http://pycurl.sourceforge.net/doc/curlobject.html

    0 讨论(0)
  • 2021-01-07 03:01

    I wouldn't bother trying to convert PHP code into python, but instead just search for a Python way of getting this answer. A little googling and it looks like this might be a duplicate:

    Oauth client initialization in python for tumblr API using Python-oauth2

    0 讨论(0)
提交回复
热议问题