2

I am working on a python script to update the app on Huawei AppGallery via Connect API. I successfully fetched the token and upload URL but not able to upload the APK/AAB. Getting this error -

{'result': {'CException': {'errorCode': 70001405, 'errorDesc': 'get no file from request!'}, 'resultCode': '70001405'}}

Here's my python script

def uploadAAB(uploadUrl, authCode, accessToken, appId):
    try:
        fileName = 'latest_hms.apk'
        headers = {
            "Authorization": "Bearer " + accessToken,
            "accept": "application/json",
            "client_id": clientId,
            "Content-Type": "multipart/form-data"
        }

        uploadBody = {
            "authCode": authCode,
            "fileCount": 1
        }

        with open(aabPath, 'rb') as f:
            f.seek(0, os.SEEK_END)
            print(f.tell()) # printing the correct size
            first_phase = requests.post(
                uploadUrl,
                files={fileName: f},
                data=uploadBody,
                headers=headers)
            
            if first_phase.status_code == 200:
                print(first_phase.json())
                body = {
                    'fileType': 5,
                    'files': [{
                        'fileName': fileName,
                        'fileDestUrl': first_phase.json()['result']['UploadFileRsp']['fileInfoList'][0]['fileDestUlr'],
                        'size': str(first_phase.json()['result']['UploadFileRsp']['fileInfoList'][0]['size'])
                    }]
                }

                fileHeader = {
                    'client_id': clientId,
                    'Authorization': 'Bearer ' + accessToken,
                }
                params = {
                    'appId': appId,
                }
                second_phase = requests.put(
                    BASE_URL + "/publish/v2/app-file-info",
                    headers=fileHeader,
                    json=body,
                    params=params)
                print(second_phase.json())
        
    except (requests.exceptions.RequestException, requests.exceptions.HTTPError, KeyError) as err:
        stopOnError(repr(err))

Please help me out here.

tronku
  • 490
  • 4
  • 12

2 Answers2

1

It seems Huawei made a change to the AppGallery API in February 2022. I don't know if this was intentional, but you must now specify a filename of "file" instead of your original filename (which worked before). See my pull request on Natgho's HMS-Publishing-API code.

Silas S. Brown
  • 1,469
  • 1
  • 17
  • 18
0

{'result': {'CException': {'errorCode': 70001405, 'errorDesc': 'get no file from request!'}, 'resultCode': '70001405'}}

This error means there is no file in the request. the file is not include successfully in the request. Please make sure the file is achievable.

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
  • i am getting the correct size of the file after `with open` I also tried the same with curl and got the same error, can you share a curl for the same request please? – tronku Feb 09 '22 at 10:02
  • It is recommended that you check whether the request include file. Could try to updated method of loading file in python script may helped. – zhangxaochen Feb 10 '22 at 03:12