卷发有效,但是python urllib2给出了400个错误请求

时间:2018-11-22 16:52:46

标签: python curl urllib2

curl命令从命令行运行

curl -X POST https://sdk.mypoolin.com/merchants_upi/request_upi_single -d "beneficiary_virtual_address=88001@upi" -d “beneficiary_amount=1” -H "apikey:API_KEY"

但是,当我尝试使用python urllib2时,它显示以下错误:

url='https://sdk.mypoolin.com/merchants_upi/request_upi_single'
parameters = urllib.urlencode({'beneficiary_virtual_address': '88001@upi','beneficiary_amount': '1'})
req = urllib2.Request(url)
req.add_header('apikey', API_KEY)
response_upi = urllib2.urlopen(req,parameters).read()
  

回溯(最近通话最近):     文件“”,第1行,位于     在urlopen中的文件“ /home/hduser/.pyenv/versions/2.7.8/lib/python2.7/urllib2.py”,第127行       返回_opener.open(URL,数据,超时)     打开文件“ /home/hduser/.pyenv/versions/2.7.8/lib/python2.7/urllib2.py”,行410       响应= meth(req,响应)     http_response中的文件“ /home/hduser/.pyenv/versions/2.7.8/lib/python2.7/urllib2.py”,第523行       'http',请求,响应,代码,msg,hdr)     文件“ /home/hduser/.pyenv/versions/2.7.8/lib/python2.7/urllib2.py”,行448,错误       返回self._call_chain(* args)     _call_chain中的文件“ /home/hduser/.pyenv/versions/2.7.8/lib/python2.7/urllib2.py”,行382       结果= func(* args)     http:// error_default中的文件“ /home/hduser/.pyenv/versions/2.7.8/lib/python2.7/urllib2.py”,第531行       引发HTTPError(req.get_full_url(),code,msg,hdrs,fp)   urllib2.HTTPError:HTTP错误400:错误请求

我还尝试将数据作为查询中的参数发送,但它给出了与上述相同的错误:

request_url = "https://sdk.mypoolin.com/merchants_upi/request_upi_single"
values = {'beneficiary_virtual_address': '88001@upi','beneficiary_amount': '1'}
request_url = request_url + "?" + urllib.urlencode(values)
data = ""
req = urllib2.Request(request_url, data)
req.add_header('apikey', MKEYUPI)
response_upi = urllib2.urlopen(req).read()

0 个答案:

没有答案