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"
CodePudding user response:
Use requests
You can do like this :
import requests
files = { 'file': ('url=https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk',
open('url=https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk',
'rb')),}
URL = 'https://api-cloud.browserstack.com/app-automate/upload'
response = requests.post(URL, files=files, auth=('YOUR_USERNAME', 'YOUR_ACCESS_KEY'))
print (response.text)
It should work fine now.
CodePudding user response:
import requests
files = {
'data': (None, '{"url": "https://www.browserstack.com/app-
live/sample-apps/android/WikipediaSample.apk"}'),
}
response = requests.post(
'https://api-cloud.browserstack.com/app-live/upload',
files=files,
auth=('USERNAME', 'ACCESS_KEY')
)