【问题标题】:How do I upload image using POST form data Python-requests如何使用 POST 表单数据 Python 请求上传图像
【发布时间】:2020-03-02 21:57:09
【问题描述】:

我正在使用 Tinder 的私有 API, 我需要在 Python 中复制下面的请求。 任何帮助将不胜感激。

POST Request to Tinder's private API - Picture

这是我当前的代码,我不知道在数据字段中放什么:

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)

【问题讨论】:

    标签: python python-requests tinder


    【解决方案1】:

    你不需要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)
    

    【讨论】:

      猜你喜欢
      • 2015-05-20
      • 2015-11-20
      • 1970-01-01
      • 1970-01-01
      • 2019-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-14
      相关资源
      最近更新 更多