pythoncurlbrowserstack

how to send post request in python for this curl command


how to send a POST request in python equivalent with this curl command

curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
-F "url=https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk"

I tried code below:

resp=requests.post(URL,headers= 
    {'YOUR_USERNAME:YOUR_ACCESS_KEY'},
  data=https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk") 

and its not working.

I don't know how to send this line "url=https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk" in POST request. "url=https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk" this is the public url of apk. and want to upload at this url "https://api-cloud.browserstack.com/app-automate/upload"

And after applying answer from below, I find the solution Thank you Everyone. Answer is -

import urllib.request

#file will download in current working directory with name app-release.apk urllib.request.urlretrieve('https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk', 'app-release.apk')

test_file = open("app-release.apk", "rb")

URL = 'https://api-cloud.browserstack.com/app-automate/upload' response = requests.post(URL, files={'file': test_file, }, auth=('YOUR_USERNAME', 'YOUR_ACCESS_KEY'))


Solution

  • And The answer of the solution, That is work for me is

    import urllib.request
    
    #file will download in current working directory with name app-release.apk 
    
    urllib.request.urlretrieve('https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk', 'app-release.apk')
    
    test_file = open("app-release.apk", "rb")
    
    URL = 'https://api-cloud.browserstack.com/app-automate/upload' response = requests.post(URL, files={'file': test_file, }, auth=('YOUR_USERNAME', 'YOUR_ACCESS_KEY'))