Curl 到 Python 请求上传到 Galaxy Store

问题描述 投票:0回答:2

Curl 这就是成功的工作。 如何将其转换为 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
2个回答
0
投票

您必须将文件属性嵌套在其自己的元组中,如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)


0
投票

https://developer.samsung.com/sdp/blog/en/2022/06/02/app-management-using-the-galaxy-store-developer-api-and-python

headers= {
          'Authorization': Authorization,
          'Accept': 'application/json',
          'service-account-id': SERVICE_ACCOUNT_ID
         }

files = {'file': open(file_path,'rb')}

payload = {
    'sessionId': Session_ID,
    }
try: 
    response = requests.post(api_url, headers=headers,files=files,data=payload)
    print(response.status_code)
    print(response.text)
except Exception as e:
    print(str(e))
© www.soinside.com 2019 - 2024. All rights reserved.