【问题标题】:Curl to Python Requests for uploading to Galaxy StoreCurl to Python 上传到 Galaxy Store 的请求
【发布时间】:2021-09-06 14:54:58
【问题描述】:

卷曲那是成功的工作。 如何将其转换为 Python 请求?

curl -i -X POST \
      -H "Content-Type:multipart/form-data" \
      -H "Authorization: Bearer <your-access-token>" \
      -H "service-account-id: <your-service-account-id>" \
      -F "file=@\"./ICON_512x512.png\";type=image/png;filename=\"ICON_512x512.png\"" \
      -F "sessionId=<session-id>" \
      "https://seller.samsungapps.com/galaxyapi/fileUpload"

我的 Python 代码有什么问题?

headers = {"Content-Type": "multipart/form-data", "Authorization": "Bearer " + <your-access-token>,
               "service-account-id": <your-service-account-id>}
    files = {
        "file": open("./ICON_512x512.png", "rb"),
        "type": "image/png",
        "filename": "ICON_512x512.png",
        'sessionId': <session-id>
    }
    response = requests.post("https://seller.samsungapps.com/galaxyapi/fileUpload",
                             headers=headers,
                             files=files)

【问题讨论】:

    标签: curl python-requests


    【解决方案1】:

    您必须将文件属性嵌套在其自己的元组中,如docs 中所述。

    试试这个。

    import requests
    
    headers = {
        'Content-Type': 'multipart/form-data',
        'Authorization': 'Bearer <your-access-token>',
        'service-account-id': '<your-service-account-id>',
    }
    
    files = {
        'file': ('./ICON_512x512.png', open('./ICON_512x512.png', 'rb')),
        'sessionId': '<session-id>',
    }
    
    response = requests.post('https://seller.samsungapps.com/galaxyapi/fileUpload', headers=headers, files=files)
    
    

    【讨论】:

      猜你喜欢
      • 2021-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-26
      • 1970-01-01
      相关资源
      最近更新 更多