首先,我不是 python 程序员。我是一个老 C 狗,学习了新的 Java 和 PHP 技巧,但是 python 看起来是一门很酷的语言。
我遇到了一个我无法完全理解的错误。错误遵循以下代码。
import httplib, urllib
url = "pdb-services-beta.nipr.com"
xml = '<?xml version="1.0"?><!DOCTYPE SCB_Request SYSTEM "http://www.nipr.com/html/SCB_XML_Request.dtd"><SCB_Request Request_Type="Create_Report"><SCB_Login_Data CustomerID="someuser" Passwd="somepass" /><SCB_Create_Report_Request Title=""><Producer_List><NIPR_Num_List_XML><NIPR_Num NIPR_Num="8980608" /><NIPR_Num NIPR_Num="7597855" /><NIPR_Num NIPR_Num="10166016" /></NIPR_Num_List_XML></Producer_List></SCB_Create_Report_Request></SCB_Request>'
params = {}
params['xmldata'] = xml
headers = {}
headers['Content-type'] = 'text/xml'
headers['Accept'] = '*/*'
headers['Content-Length'] = "%d" % len(xml)
connection = httplib.HTTPSConnection(url)
connection.set_debuglevel(1)
connection.request("POST", "/pdb-xml-reports/scb_xmlclient.cgi", params, headers)
response = connection.getresponse()
print response.status, response.reason
data = response.read()
print data
connection.close
这是错误:
回溯(最近一次通话最后): 文件“C:\Python27\tutorial.py”,第 14 行,在 connection.request("POST", "/pdb-xml-reports/scb_xmlclient.cgi", params, headers) 文件“C:\Python27\lib\httplib.py”,第 958 行,在请求 self._send_request(method, url, body, headers) _send_request self.endheaders(body) 中的文件“C:\Python27\lib\httplib.py”,第 992 行 文件“C:\Python27\lib\httplib.py”,第 954 行,在 endheaders self._send_output(message_body) _send_output self.send(message_body) 中的文件“C:\Python27\lib\httplib.py”,第 818 行 文件“C:\Python27\lib\httplib.py”,第 790 行,在发送 self.sock.sendall(data) 文件“C:\Python27\lib\ssl.py”,第 229 行,在 sendall v = self.send(data[count:]) TypeError:不可散列的类型
我的日志文件显示 xmldata 参数为空。
有任何想法吗?