简体   繁体   中英

python upload file with curl

i'm trying to upload an apk to server the code i used to upload using curl is written like this:

curl -u "musername:mypass" -X POST "https://myurl/upload" -F "file=@D:\path\to\location.apk"

i tried to make a script using python with requests library like this:

response = requests.post(
            self.urlUpload,
            files={"file" : open(self.apkLocation, 'r')},
            auth=(self.BSUsername, self.BSToken)
        )

but it gives me errors:

{"error":"Malformed archive"}

anyone knows why this erros appeared?

Have you had a chance to try something like below?

import requests

    files = {
        'file': ('/path/to/app/file/Application-debug.apk', open('/path/to/app/file/Application-debug.apk', 'rb')),
    }
    response = requests.post('https://api-cloud.browserstack.com/app-automate/upload', 
                files=files, 
                auth=('BSUsername ', 'BSToken'))
    print (response.text)#THE APP URL (bs://<hashed appid>) RETURNED IN THE RESPONSE OF THIE CALL

Check the BrowserStack REST API doc here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM