0

I am a beginner trying to learn REST API programming through Python 2.7 to get data from Socialcast API. From my research it looks like requests or urllib2 would work. I need to authenticate with username and id for the API. I tried using urllib2 and it gave me error 401.

Which one should I use? My goal is to produce .csv files from the data so I can visualize it. Thank you in advance.

1
  • Both libraries can be used for this. If one of them is giving you an error, post a question about that error (and include your code).
    – jwodder
    Commented Jun 23, 2017 at 17:30

1 Answer 1

0

The question will yield a bit of an opinion based response, but I would suggest using Requests. I find that when making request that require parameters using Requests is easier to manage. An example for the Socialcast using Requests would be

parameters={"email" : emailAddress, "passoword" : password}
r = requests.post(postUrl, parameters)

The post url would be the url to make the post request and emailAddress and password would be the vales you use to login in.

For the csv, take a look here which includes a tutorial on going from json to csv.

3
  • I tried your code and got this error: '>>> parameters = {"username" : emailAddress, "password" : password} Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'emailAddress' is not defined'
    – Evan Mann
    Commented Jun 23, 2017 at 18:08
  • @EvanMann emailAddress and password are just place holders for your email and password
    – cbolles
    Commented Jun 23, 2017 at 18:09
  • It was fixed by making my username and password strings. I didn't have quotes around them. Thanks!
    – Evan Mann
    Commented Jun 23, 2017 at 19:07

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.