python - 如何使用 POST 表单数据 Python 请求上传图像
问题描述
我正在使用 Tinder 的私有 API,我需要在下面用 Python 复制请求。任何帮助将不胜感激。
对 Tinder 的私有 API 的 POST 请求 - 图片
这是我当前的代码,我不知道在数据字段中放什么:
url = "https://api.gotinder.com/v2/onboarding/photo?requested=tinder_rules&requested=name&requested=birth_date&requested=gender&requested=custom_gender&requested=show_gender_on_profile&requested=photos&requested=email&requested=allow_email_marketing&requested=consents&requested=schools&requested=interested_in_gender&requested=show_same_orientation_first&requested=show_orientation_on_profile&requested=sexual_orientations"
header = {
"token": onboarding_token,
"os-version": "29",
"encoded-device-model": "WU06NZt",
"mobile-country-code": "255",
"encoded-device-carrier": "u2ascI",
"appsflyer-id": "1583173259413-9570632540896010457",
"app-session-id": "dff122a6-b476-6497-e918-30780a3fe0f2",
"mobile-network-code": "01",
"persistent-device-id": "b2be392ff451af50",
"accept-language": "en",
"x-supported-image-formats": "webp",
"os-version": "29",
"user-agent": "Tinder Android Version 11.6.0",
"install-id": "aAOLMKioAx2",
"platform": "android",
"tinder-version": "11.6.0",
"app-session-time-elapsed": "31851",
"app-version": "3665",
"Content-Type": "multipart/form-data; boundary=cloyjwdgfespkeflygwqmaaapnqambnjhdpbajej",
"Accept-Encoding": "gzip",
"Accept": "*/*"
}
payload = {"fields":[{"data":1,"name":"gender"}]}
r = requests.post(url, data={ }, headers=header, verify=True)
print(r.response)
解决方案
您不需要verify=True
并且需要像这样发送参数中的图片和files
参数中的其他两个字段data
。
url = "https://api.gotinder.com/v2/onboarding/photo?requested=name&requested=birth_date&requested=gender&requested=custom_gender&requested=show_gender_on_profile&requested=photos&requested=schools&requested=consents&requested=videos_processing&requested=sexual_orientations&requested=show_same_orientation_first&requested=show_orientation_on_profile&requested=interested_in_gender&requested=tinder_rules"
payload = {'num_media_pending': '0',
'type': 'photo'}
files = [
('photo', open(file_name,'rb'))
]
headers = {
'user-agent': 'Tinder/11.12.0 (iPhone; iOS 13.3.1; Scale/2.00)',
'persistent-device-id': 'ADEF242C6C43497981B7482AFA4AE57',
'app-session-time-elapsed': '1453.912697076797485',
'x-supported-image-formats': 'webp, jpeg',
'platform': 'ios',
'token': onboarding_token,
'accept-language': 'en-us',
'tinder-version': '11.12.0',
'accept': '*/*',
'app-version': '3463',
'app-session-id': '12CE45F5-75CE-4E96-B402-CCAD8007DE43',
'os-version': '130000300001',
'accept-encoding': 'gzip, deflate, br',
'content-type': 'multipart/form-data; boundary=Boundary-13A00F53-F569-4FDB-B9B0-B160ECC11322',
'user-session-time-elapsed': '408.918367587797123'
}
res = requests.post(url, headers=headers, data = payload, files = files)
推荐阅读
- json - 如何使用 for 循环在 JSON 中创建多个记录(又名对象)
- python - 如果登录 Django,我如何获取用户 ID?
- python-3.x - 优化不尊重约束
- python - 反向传播中的浮点溢出问题
- python - 如何使用 conn.send() 向客户端发送数据
- c# - 无法在 JetBrains Rider 中加载解决方案
- javascript - 在特定缩放级别触发事件
- python - Pandas Python - 对其他人进行分组计数
- c++ - Boost Asio - boost::bind 导致程序崩溃
- azure - Azure AD B2C:从 Json 数组中提取单个项目