Help with cURL in Python

后端 未结 4 1548
-上瘾入骨i
-上瘾入骨i 2021-01-07 05:05

I have to POST a request to a server. In the API documentation of the website there is this example that uses cURL in PHP:

$ch = curl_init();
curl_setopt($ch         


        
4条回答
  •  渐次进展
    2021-01-07 05:36

    Taking your code, this should actually work.

     import urllib 
     import urllib2
    
     url = 'http://api.website.com/' 
     values = {'some_key':'some_value'} 
     data = urllib.urlencode(values) 
     req = urllib2.Request(url, data) 
     response = urllib2.urlopen(req) 
     page = response.read()
     print page + '\n\n'
    

    What is the error you are getting?

提交回复
热议问题