in Education by
I want to execute a curl command in python. curl -d @request.json --header "Content-Type: application/json" https://www.googleapis.com/qpxExpress/v1/trips/search?key=mykeyhere There is a request.json file to be sent to get response. I tried to write code, but it does not work. import pycurl import StringIO response = StringIO.StringIO() c = pycurl.Curl() c.setopt(c.URL, 'https://www.googleapis.com/qpxExpress/v1/trips/search?key=mykeyhere') c.setopt(c.WRITEFUNCTION, response.write) c.setopt(c.HTTPHEADER, ['Content-Type: application/json','Accept-Charset: UTF-8']) c.setopt(c.POSTFIELDS, '@request.json') c.perform() c.close() print response.getvalue() response.close() The error message is 'Parse Error'. Help me fix it. Select the correct answer from above options

1 Answer

0 votes
by
Maybe you should consider using the Requests library. If you simply take an example with JSON response content, it would be something like: import requests r = requests.get('https://github.com/timeline.json') r.json() For more information just visit the Quickstart section, they will provide you with lots of working examples. For your specific curl translation: import requests url = 'https://www.googleapis.com/qpxExpress/v1/trips/search?key=mykeyhere' payload = open("request.json") headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8'} r = requests.post(url, data=payload, headers=headers) You can use the following video tutorials to clear all your doubts:- If You want to learn python for data science visit this python course by Intellipaat.

Related questions

0 votes
    I want to execute a curl command in python. curl -d @request.json --header "Content-Type: application/ ... Core Questions, Core Hadoop MCQ,core interview questions for experienced...
asked Oct 31, 2021 in Education by JackTerrance
0 votes
    I want to execute a curl command in Python. Usually, I just need to enter the command in the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I want to draw arrows (that change size dynamically) within a Label or any other widget. I have ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 25, 2022 in Education by JackTerrance
0 votes
    I want to run a python script from a shell script. I have been able to run it from the "command ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 26, 2022 in Education by JackTerrance
0 votes
    I want to run a python script from a shell script. I have been able to run it from the "command ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 10, 2022 in Education by JackTerrance
0 votes
    I have a fixed list of services in a Linux server. I want to check the status of these services ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    I am aware of the die() command in PHP which stops a script early. How can I do this in Python? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    How to check which Python version is interpreting my script? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    I am trying to write my below pinging script results into the Text file, but I am getting an error message. ... object is not iterable Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    URL is http://*.*.*.*/100/?id=1&version=1 params is {"cityId": "110000", "query": {" ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 27, 2022 in Education by JackTerrance
0 votes
    Within a python script can I call an external command? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I am facing problems in _files which isn't defined if I execute the script with exec, ececfile and in _module_ ... help me with this? Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    I need to know how to use the delete_channel command in discord.py may someone please post a code sample ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I need to know how to use the delete_channel command in discord.py may someone please post a code sample ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 10, 2022 in Education by JackTerrance
0 votes
    I installed Anaconda3 4.4.0 (32 bit) on my Windows 7 Professional machine and imported NumPy and Pandas on Jupyter ... I make it work? Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
...