Python PUT请求 - 无效语法

时间:2017-09-18 15:04:13

标签: python api python-requests put

我正在使用接受PUT请求的API。我试图添加一个新的描述,但每当我在我的脚本中使用它时,它告诉我无效的语法。任何帮助解决这个问题都将不胜感激。

    payload = {'description' : '<p>This is just some text...</p>'}
    r = requests.put('REMOVED/{}/REMOVED/{}'.format(course['c_id'], 
    course['a_id']), data = payload, headers = {'Authorization': 'REMOVED')

1 个答案:

答案 0 :(得分:0)

这可能是因为缺少大括号

(... data = payload, headers = {'Authorization': 'REMOVED'})
                                                         ^^^

所以,你最好做的是设置变量而不是对象/逻辑本身。

payload = {'description' : '<p>This is just some text...</p>'}
course_id = course['c_id']
another_id = course['a_id']
url = 'https://yoururl.com/{}/{}'.format(course_id, another_id)
headers = {'Authorization': 'REMOVED'}

r = requests.put(url, data = payload, headers = headers)

这将让您轻松检查错误。