相关疑难解决方法(0)

在Python请求中的字典中的PUT字典

我想发送一个具有以下数据结构的PUT请求:

{ body : { version: integer, file_id: string }}
Run Code Online (Sandbox Code Playgroud)

这是客户端代码:

def check_id():
    id = request.form['id']
    res = logic.is_id_valid(id)

    file_uuid = request.form['file_id']
    url = 'http://localhost:8050/firmwares'
    r = requests.put(url = url, data = {'body' : {'version': id, 'file_id': str(file_uuid)}})
Run Code Online (Sandbox Code Playgroud)

这是服务器代码:

api.add_resource(resources.FirmwareNewVerUpload, '/firmwares')

class FirmwareNewVerUpload(rest.Resource):
    def put(self):
        try:
            args = parser.parse_args()
        except:
            print traceback.format_exc()

        print 'data: ', str(args['body']), ' type: ', type(args['body'])

        return
Run Code Online (Sandbox Code Playgroud)

服务器打印:

data:  version  type:  <type 'unicode'>
Run Code Online (Sandbox Code Playgroud)

这个结果不是我想要的.而不是内部字典我得到一个名称为一个字典键的字符串.如果我将'版本'更改为'ver'

    r = requests.put(url = url, data = {'body' : {'ver': id, 'file_id': …
Run Code Online (Sandbox Code Playgroud)

python dictionary python-requests

3
推荐指数
1
解决办法
3426
查看次数

标签 统计

dictionary ×1

python ×1

python-requests ×1