尝试使用urllib3发布JSON编码的数据.只是希望我的POST有效负载是原始JSON字符串,内容类型为application/json.我只是看不出怎么做.
urllib3文档描述了在"字段"中发布数据,即具有(键,值)对的字典,就像HTML表单是如何使用URL进行URL编码的.但我不想这样做.
我能得到的最接近的是(我只是猜到了数据的放置位置,因为它没有记录在我能找到的任何地方):
http = urllib3.PoolManager()
headers = urllib3.util.make_headers(basic_auth=key+":")
r = http.request_encode_body('POST', path, json.dumps(payload), headers=headers)
Run Code Online (Sandbox Code Playgroud)
这导致这个urllib3错误:
File "C:\Python27\lib\site-packages\urllib3-1.7.1-py2.7.egg\urllib3\filepost.py", line 44, in iter_field_objects
yield RequestField.from_tuples(*field)
TypeError: from_tuples() takes exactly 3 arguments (2 given)
Run Code Online (Sandbox Code Playgroud)
感谢您的任何指示!