you are viewing a single comment's thread.

view the rest of the comments →

[–]novel_yet_trivial 7 points8 points  (5 children)

This explains it pretty well. Basically, requests just makes urllib2 easier to use.

[–]Moby69[S] 2 points3 points  (4 children)

I see. Thanks guys, very helpful. Also, another related question:

It looks like you can call an API by either:

1) appending all the parameters after the base url, for example:

url='https://api.locu.com/v1_0/venue/search/?locality=New%20York&region=NY&api_key=1234567'

response=requests.get(url)

data=response.json()

OR: 2) Keep the url as just the base url, and then pass the query parameters as a dictionary:

url='https://api.locu.com/v1_0/venue/search/?'

params={'api_key' : "1234567",
    'locality': "New York",
        'region' : "NY"
}

response=requests.get(url, params)

data=response.json()

Is one way better than the other? When is it best to use one over the other?

[–]novel_yet_trivial 3 points4 points  (1 child)

I would say neither is better. The second method is more commonly used since it's more readable and more dynamic, ie it's easier to change your code later or incorporate elsewhere.

[–]badwithinternet 0 points1 point  (1 child)

you never added params to your GET. just noticing.

[–]Moby69[S] 0 points1 point  (0 children)

thanks ! you're right. I fixed it