简体   繁体   中英

How can i convert bash curl request to python

I am a beginner in python. So, below is my code. This was originally written in bash and now I want to write an equivalent code for this in python. However, I cannot wrap my head around it. Please help.

I have a config file called config.py where all the variables are defined. For this particular context, both apimessage and reportingapi are variable which is being called from config.py

I have imported it in the main.py. When i print them directly, they get printed but inside this curl command, it does not.

Thanks in advance.

def encoding_complete():
    
    response = request.post(curl --write-out %{http_code} --silent --output /dev/null -d **apimessage** -X POST **reportingapi**)

As I understood your main problem is you can't run bash commands in python. You need to have another library subprocess for that.

import subprocess
process = subprocess.Popen("your bash command goes here as a string")

refer Running Bash commands in Python

If your bash command is correct it would do. You can't request.get and curl inside it.

@J.Smith Thanks. Your solution pointed me to the right direction.

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