2

I am having trouble executing the following shell command. I'm in windows 10. I had to delete the user authorization here and left it as 'tktk' as i dind't want my authorization out here like that.

curl 'https://pegasus-test.etflogic.io/portfolio/analyze' -H 'authority: pegasus-test.etflogic.io' -H 'pragma: no-cache' -H 'cache-control: no-cache' -H 'accept: application/json' -H 'authorization: tktk' -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36' -H 'content-type: application/json' -H 'origin: https://akita.etflogic.com' -H 'sec-fetch-site: cross-site' -H 'sec-fetch-mode: cors' -H 'referer: https://akita.etflogic.com/portfolio-analysis' -H 'accept-encoding: gzip, deflate, br' -H 'accept-language: en-US,en;q=0.9' --data-binary '{"portfolio":{"currency":"usd","id":"8576e266-c6f4-44fe-a6a6-9c64869b55dd","name":"test1","records":[{"locale":"US","id":"df92931e-3063-4889-8e4b-100c66f14d22","name":"SSGA SPDR S&P 500 - SSgA Active Trust","secid":549535,"size":100,"ticker":"SPY US"}],"size_type":"notional","type":"primary"}}' --compressed > /tmp/jsonpayload

I stored the above command in a test.sh file I'm having trouble executing the above shell command. It works on the linux terminal. But it doesn't work on my windows cmd. I need to read the above url, get the json object and do some analysis with it.

What i tried:

import subprocess 
ans = subprocess.Popen(["bash",os.path.join(os.getcwd(), 'test.sh')])

This fails. ok...

I tried then...

subprocess.call(['test.sh'])

I'm getting error '%1 is not a valid Win32 application'

5
  • Why don't you use Python's requests module instead of curl? Commented Feb 18, 2020 at 22:35
  • Probably because curl doesn't come with windows by default. Did you try installing curl for windows? Commented Feb 18, 2020 at 22:38
  • yea I did. but it doesn't work still Commented Feb 18, 2020 at 22:51
  • 1
    Before calling the shell command from python, I would recommend to try to call it from cmd or the Powershell. Did you get "not a valid Win32 application" for both tries ? Commented Feb 18, 2020 at 23:08
  • This fails. Fails how? I'm getting error '%1 is not a valid Win32 application' Is that the entire error message? Commented Feb 19, 2020 at 0:15

2 Answers 2

1

I copied your test.sh code into my own test.sh file, and tested a few different things.

Try using os.system for calling your command instead of methods from subprocess.

This worked for me:

import os
os.system(os.getcwd() + '/test.sh')

If you prefer os.path.join(os.getcwd(), 'test.sh') instead of what I have here, you can use that too, there's no major difference.

I hope this solves your problem :)

Sign up to request clarification or add additional context in comments.

1 Comment

I’m not at work atm. When I get back tomorrow morning, I will check this. Thanks
0

try:

# Importing the necessary packages
$ from subprocess import call  

# Executing the test.sh script
$ call('sh test.sh 2>/dev/null', shell=True)

1 Comment

While this code may provide a solution to OP's problem, it is highly recommended that you provide additional context regarding why and/or how this code answers the question. Code only answers typically become useless in the long-run because future viewers experiencing similar problems cannot understand the reasoning behind the solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.