-1

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**)
  • 1
    What have you tried ? Have you read requests example and docs ? – azro Jun 07 '21 at 17:32
  • @azro I tried going through many documentation but haven't got a clue as how to find a workaround – Bardan Pokhrel Jun 07 '21 at 17:35
  • 1
    I suggest starting with something simple. First try to get a web page from a given url. Then try to post data to a url. Continue building up from there. – Code-Apprentice Jun 07 '21 at 17:38
  • 1
    First, know what each curl option does. Then find the equivalent parameter to use in `request.post(...)`. –  Jun 07 '21 at 17:39

2 Answers2

1

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
  • 362
  • 1
  • 10
0

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