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