【发布时间】:2017-03-22 04:53:09
【问题描述】:
我正在尝试检查网站中是否已存在电子邮件。目前使用 Postman 的示例 Python 代码。
有效的示例代码:
import requests
url = "https://registration.mercadolivre.com.br/registration/"
payload = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"signUp.email\"\r\n\r\ntest@hotmail.com\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"signUp.repEmail\"\r\n\r\ntest@hotmail.com\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"signUp.newsletter\"\r\n\r\ntrue\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"source\"\r\n\r\nmercadolibre\r\n-----011000010111000001101001--"
headers = {
'content-type': "multipart/form-data; boundary=---011000010111000001101001",
'cache-control': "no-cache",
'postman-token': "179cabe2-dd22-490e-8fbd-15bf2977feb5"
}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
我不确定 Postman 为什么要在该字符串中编码有效负载。当我尝试传递字典时,它不再起作用了
不起作用的代码:
import requests
url = "https://registration.mercadolivre.com.br/registration/"
payload = { 'signUp.email': 'test@hotmail.com',
'signUp.repEmail': 'test@hotmail.com',
'signUp.newsletter': 'true',
'source': 'mercadolibre' }
headers = {
'content-type': "multipart/form-data; boundary=---011000010111000001101001",
'cache-control': "no-cache",
'postman-token': "22a12fa5-5f68-685c-124d-db0ef6eb334c"
}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
我想知道为什么我不能传递 json 或字典。
【问题讨论】:
标签: python python-requests postman