幸福的魔王 2018-05-08 03:54 采纳率: 0%
浏览 3027
已结题

python3.65 urllib.request.Request()增加header报错

coding:utf-8

import urllib.request
import urllib.parse

url = 'http://192.168.**.**:9080/api/transactions'
header = {
'Content-Type': 'application/json'
}
values ={
"currentToken": {
"simplifiedName": "ETH",
"address": "0x5bcd4d0508bc86c48760d0805962261d260d7a88"
},
"txid": ""
}
data = urllib.parse.urlencode(values)
data = data.encode(encoding='UTF-8')
request = urllib.request.Request(url, data, header)
#request = urllib.request.Request(url, data)
print("111")
html = urllib.request.urlopen(request)
print("222")
html =html.read().decode('utf-8')
print(html)

#返回结果 报错
D:\tool\Python36\python.exe D:/Users/Administrator/PycharmProjects/coinPlatform/test/test6.py
111
Traceback (most recent call last):
File "D:/Users/Administrator/PycharmProjects/coinPlatform/test/test6.py", line 21, in
html = urllib.request.urlopen(request)
File "D:\tool\Python36\lib\urllib\request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "D:\tool\Python36\lib\urllib\request.py", line 532, in open
response = meth(req, response)
File "D:\tool\Python36\lib\urllib\request.py", line 642, in http_response
'http', request, response, code, msg, hdrs)
File "D:\tool\Python36\lib\urllib\request.py", line 570, in error
return self._call_chain(*args)
File "D:\tool\Python36\lib\urllib\request.py", line 504, in _call_chain
result = func(*args)
File "D:\tool\Python36\lib\urllib\request.py", line 650, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found

Process finished with exit code 1

coding:utf-8

import urllib.request
import urllib.parse

url = 'http://192.168.**.**:9080/api/transactions'
header = {
'Content-Type': 'application/json'
}
values ={
"currentToken": {
"simplifiedName": "ETH",
"address": "0x5bcd4d0508bc86c48760d0805962261d260d7a88"
},
"txid": ""
}
data = urllib.parse.urlencode(values)
data = data.encode(encoding='UTF-8')
#request = urllib.request.Request(url, data, header)
request = urllib.request.Request(url, data)
print("111")
html = urllib.request.urlopen(request)
print("222")
html =html.read().decode('utf-8')
print(html)

返回结果 成功 但没得到想要的结果
D:\tool\Python36\python.exe D:/Users/Administrator/PycharmProjects/coinPlatform/test/test6.py
111
222
{"code":0,"message":"success","data":{"currentToken":{},"transactions":[]}}

Process finished with exit code 0

  • 写回答

4条回答 默认 最新

  • dabocaiqq 2018-05-08 08:24
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 求解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果