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 questions and answers, questions pdf, question bank, questions and answers pdf, mcq on pdf, questions and solutions, mcq Test , Interview questions, Questions for Interview, MCQ (Multiple Choice Questions),Core Questions, Core Hadoop MCQ,core interview questions for experienced

1 Answer

0 votes
by
 
Best answer
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
    Is there any way or any command which I can use in command prompt to know the version of Hadoop? Also, ... ,Core Questions, Core Hadoop MCQ,core interview questions for experienced...
asked Oct 31, 2021 in Education by JackTerrance
0 votes
    Could anyone tell me how good Intellipaat's Data Science course is? Select the correct answer from above ... Questions, Core Hadoop MCQ,core interview questions for experienced...
asked Jan 6, 2022 in Education by JackTerrance
0 votes
    Could someone share with me the best way to learn Data Analytics from scratch? Select the correct answer ... Questions, Core Hadoop MCQ,core interview questions for experienced...
asked Jan 6, 2022 in Education by JackTerrance
0 votes
    Can someone please tell me a quick way to convert a nested list of data whose length is 100 and each item is a list of ... 100 rows and 10 columns? I am attaching a sample data: 5...
asked Dec 21, 2021 in Education by JackTerrance
0 votes
    How can I check if a given value is contained in a vector? Select the correct answer from above options ... Core Questions, Core Hadoop MCQ,core interview questions for experienced...
asked Dec 21, 2021 in Education by JackTerrance
0 votes
    What exactly is the difference between groupby("x").count and groupby("x").size in Pandas? Select the ... ,Core Questions, Core Hadoop MCQ,core interview questions for experienced...
asked Oct 31, 2021 in Education by JackTerrance
0 votes
    Here is the code class method { int counter = 0; public static void main(String[] args) { System.out. ... ),Core Questions, Core Hadoop MCQ,core interview questions for experienced...
asked Oct 31, 2021 in Education by JackTerrance
0 votes
    What is meant by a memory leak in Java, and how to implement it. Select the correct answer from above ... ,Core Questions, Core Hadoop MCQ,core interview questions for experienced...
asked Oct 31, 2021 in Education by JackTerrance
0 votes
    How can I convert an RDD to a dataframe? I converted a data frame to rdd using .rdd. After processing ... ,Core Questions, Core Hadoop MCQ,core interview questions for experienced...
asked Oct 31, 2021 in Education by JackTerrance
0 votes
    How can I find the size of a directory, using Hadoop? Select the correct answer from above options ... Questions, Core Hadoop MCQ,core interview questions for experienced...
asked Oct 31, 2021 in Education by JackTerrance
0 votes
    Can someone explain the basic difference that distinguishes s3n, s3a and s3 in Hadoop? Technically how are ... Questions, Core Hadoop MCQ,core interview questions for experienced...
asked Oct 31, 2021 in Education by JackTerrance
0 votes
    Can someone tell me what is metadata? What is the difference between Internal tables and external tables in ... Questions, Core Hadoop MCQ,core interview questions for experienced...
asked Oct 31, 2021 in Education by JackTerrance
0 votes
    I tried moving the files using WinSCP, but it didn't help. So, I wanna know how can I copy files ... ),Core Questions, Core Hadoop MCQ,core interview questions for experienced...
asked Oct 31, 2021 in Education by JackTerrance
0 votes
    In the hive, partitioning and bucketing a table, both are done on a column. But how exactly are they ... ,Core Questions, Core Hadoop MCQ,core interview questions for experienced...
asked Oct 31, 2021 in Education by JackTerrance
0 votes
    Hi, I am using MapReduce and there are so many steps in it. I want the value of the last reduced step ... ),Core Questions, Core Hadoop MCQ,core interview questions for experienced...
asked Oct 31, 2021 in Education by JackTerrance
...