Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
能够卷曲POST请求,但使用请求的Python脚本返回500错误?_Python_Curl_Python Requests - Fatal编程技术网

能够卷曲POST请求,但使用请求的Python脚本返回500错误?

能够卷曲POST请求,但使用请求的Python脚本返回500错误?,python,curl,python-requests,Python,Curl,Python Requests,我在Django有一个微服务,它通过POST请求获取一个postalcode,并返回附近的postalcode列表 我知道这项服务是有效的,因为我可以把它卷曲 curl http://172.17.0.6:80/zipcode/ -d "postalcode=97201" 返回 {"postalcodes": ["97201", "97239", "97205", "97204", "97228", "97238", "97207", "97269", "97268", "97240", "9

我在Django有一个微服务,它通过POST请求获取一个postalcode,并返回附近的postalcode列表

我知道这项服务是有效的,因为我可以把它卷曲

curl http://172.17.0.6:80/zipcode/ -d "postalcode=97201"
返回

{"postalcodes": ["97201", "97239", "97205", "97204", "97228", "97238", "97207", "97269", "97268", "97240", "97250", "97242"]}
我正在尝试编写一个脚本,它将成为我的其他微服务如何与该服务通信的基础,问题是该脚本返回了一个500错误,我无法确定我做错了什么

python脚本:

import requests
def calculate_postalcodes(postalcode):
    url="http://172.17.0.6:80/zipcode/"
    params ={'postalcode':postalcode}
    data = requests.post(url=url, params=params)
    # output = data.json()
    # zipcodes = output['postalcodes']
    return data.text


postalcodess = calculate_postalcodes('97201')
print postalcodess
django原木

mypostalcode = request.POST['postalcode']
File "/usr/local/lib/python2.7/dist-packages/django/utils/datastructures.py", line 85, in __getitem__
raise MultiValueDictKeyError(repr(key))
MultiValueDictKeyError: "'postalcode'"
因为我们知道该服务与curl请求一起工作,所以我选择不包含代码片段。基本上,我只是尝试通过POST请求传递zipcode,传递方式与我的CURL请求相同。

data = requests.post(url=url, params=params)


修正了这个问题。我的Web服务器不允许通过URL传递参数,这就是params所做的(而数据通过http请求传递)

hmmm。。您是否可以查看服务接收的参数。在flask中,我可以执行类似于
print(requests.args)
edit的操作:我认为
request.POST.keys()
应该可以解决这个问题,我的位置应用程序不允许使用参数而不是数据。
data = requests.post(url=url, data=params)