通过使用urllib在新行中使用数据而没有百分比%

时间:2016-03-01 13:35:16

标签: python urllib

这可能很棘手,但显然当我推送一些参数时,我会得到这种格式的代码:

  

CLIENTPORT = 9999&安培; RESPONSETIME = 2403&安培;则httpStatus = GOOD&安培;服务器IP = 172.16.1.1&安培;服务名= GET +%2Fqantas%2Fdom2%2Fprice&安培; UNIQUEID = 654901&安培; clientip = 172.16.1.1&安培;结束时间= 2016年3月1日+ 17%3A10%3A08&安培;开始时间= 2016年3月1日+ 17%3A08%3A08&安培; httpstatuscode = 200安培; serverport = 9999&安培;类型= 1

服务器的另一端有一种特定的格式,我想要这种格式的数据,其中每个参数都有没有%符号的新行。我们该怎么做呢

654901
1
172.16.1.1
9999
172.16.1.1
9999
GOOD
200
2016-03-1 17:08:08
2403
2016-03-1 17:10:08
GET /qantas/price

我正在运行的代码

import urllib
params = urllib.urlencode(
{'uniqueID': '654901',
'type': '1\n',
'clientip': '172.16.1.1',
'clientport': '9999',
'serverIP': '172.16.1.1',
'serverport': '9999',
'httpstatus': 'GOOD',
'httpstatuscode': '200',
'starttime': '2016-03-1 17:08:08',
'responsetime': '2403',
'endtime': '2016-03-1 17:10:08',
'servicename': 'GET /qantas/price'
})
print type(params)
f = urllib.urlopen("http://142.16.1.90:9111/TxnService", params)
print f.read()
print params

1 个答案:

答案 0 :(得分:1)

您是否尝试过请求模块?

import requests

payload = {'uniqueID': '654901',
'type': '1\n',
'clientip': '172.16.1.1',
'clientport': '9999',
'serverIP': '172.16.1.1',
'serverport': '9999',
'httpstatus': 'GOOD',
'httpstatuscode': '200',
'starttime': '2016-03-1 17:08:08',
'responsetime': '2403',
'endtime': '2016-03-1 17:10:08',
'servicename': 'GET /qantas/price'
}

r = requests.post("http://142.16.1.90:9111/TxnService", data = payload)
print(r.text)
相关问题