Discussion:
[Tutor] DEALING WITH API
Gaurav Lathwal
2015-08-07 09:14:11 UTC
Permalink
Hello everyone. :))

This time I am trying to fetch the required data using the API of the
website.
But, the problem I am having is I don't know how to make the request
properly.
When I enter the required URL in my browser, it downloads a .tgz which
includes all the updates that have taken place on the website in the last
24 hours.
So, when I use urlopen on the same url, & I try to read it, all I get is
gibberish.

Any help, please ?
If I am unable to solve this problem, I am quitting programming, I have had
enough bad experiences. :\ :\
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Emile van Sebille
2015-08-07 17:46:00 UTC
Permalink
Post by Gaurav Lathwal
Hello everyone. :))
This time I am trying to fetch the required data using the API of the
website.
But, the problem I am having is I don't know how to make the request
properly.
When I enter the required URL in my browser, it downloads a .tgz which
includes all the updates that have taken place on the website in the last
24 hours.
I'd normally use wget to retrieve tgz files and not a browser.

Emile
Post by Gaurav Lathwal
So, when I use urlopen on the same url, & I try to read it, all I get is
gibberish.
Any help, please ?
If I am unable to solve this problem, I am quitting programming, I have had
enough bad experiences. :\ :\
_______________________________________________
https://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Joel Goldstick
2015-08-07 17:55:50 UTC
Permalink
Post by Emile van Sebille
Post by Gaurav Lathwal
Hello everyone. :))
This time I am trying to fetch the required data using the API of the
website.
But, the problem I am having is I don't know how to make the request
properly.
When I enter the required URL in my browser, it downloads a .tgz which
includes all the updates that have taken place on the website in the last
24 hours.
There is a third party module called Requests which is much easier to
use than the standard python urllib stuff. Check it out.
http://docs.python-requests.org/en/latest/
Post by Emile van Sebille
I'd normally use wget to retrieve tgz files and not a browser.
Emile
Post by Gaurav Lathwal
So, when I use urlopen on the same url, & I try to read it, all I get is
gibberish.
Any help, please ?
If I am unable to solve this problem, I am quitting programming, I have had
enough bad experiences. :\ :\
_______________________________________________
https://mail.python.org/mailman/listinfo/tutor
_______________________________________________
https://mail.python.org/mailman/listinfo/tutor
--
Joel Goldstick
http://joelgoldstick.com
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Alan Gauld
2015-08-07 17:55:50 UTC
Permalink
Post by Gaurav Lathwal
This time I am trying to fetch the required data using the API of the
website.
Which website? Don;t assume we can remember from your previous post
or that we will want to go trawling the archives.

The easier you make it for us to answer the more likely you are
to get good answers.
Post by Gaurav Lathwal
But, the problem I am having is I don't know how to make the request
properly.
When I enter the required URL in my browser, it downloads a .tgz which
includes all the updates that have taken place on the website in the last
24 hours.
Can we see exactly what URLyou type in?
Post by Gaurav Lathwal
So, when I use urlopen on the same url, & I try to read it, all I get is
gibberish.
Can you show us the actual code and the actual gibberish.
Are you sure the gibberish is not just the tgz binary file
contents? And if so why are you sure?
ie. What did you do to test it?

The more detailed facts we have the more we can help.
code, error messages, python version, OS, - all help.
Post by Gaurav Lathwal
If I am unable to solve this problem, I am quitting programming, I have had
enough bad experiences. :\ :\
One thing I've learned about programming over the last 40 years
is that you always have to go through a lot of trial and error to
get new stuff working. Think of it as experimenting and having
fun discovering new things and it becomes less painful.
Think of it as just inconvenient errors and its just
frustrating... It's all about the state of mind :-)
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Gaurav Lathwal
2015-08-07 20:55:53 UTC
Permalink
Thank you everyone for your help.

I managed to make a somewhat working model of what I had in my mind.
I will be sharing my code with you. Please tell me how to improve it. I
think it could be done in much less number of lines.
http://pastie.org/10336178

The first part which is handling the download is someone else's code I
found on StackOverflow. I am still unclear as to why it works.
Post by Gaurav Lathwal
This time I am trying to fetch the required data using the API of the
Post by Gaurav Lathwal
website.
Which website? Don;t assume we can remember from your previous post
or that we will want to go trawling the archives.
The easier you make it for us to answer the more likely you are
to get good answers.
But, the problem I am having is I don't know how to make the request
Post by Gaurav Lathwal
properly.
When I enter the required URL in my browser, it downloads a .tgz which
includes all the updates that have taken place on the website in the last
24 hours.
Can we see exactly what URLyou type in?
So, when I use urlopen on the same url, & I try to read it, all I get is
Post by Gaurav Lathwal
gibberish.
Can you show us the actual code and the actual gibberish.
Are you sure the gibberish is not just the tgz binary file
contents? And if so why are you sure?
ie. What did you do to test it?
The more detailed facts we have the more we can help.
code, error messages, python version, OS, - all help.
If I am unable to solve this problem, I am quitting programming, I have had
Post by Gaurav Lathwal
enough bad experiences. :\ :\
One thing I've learned about programming over the last 40 years
is that you always have to go through a lot of trial and error to
get new stuff working. Think of it as experimenting and having
fun discovering new things and it becomes less painful.
Think of it as just inconvenient errors and its just
frustrating... It's all about the state of mind :-)
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
http://www.flickr.com/photos/alangauldphotos
_______________________________________________
https://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Continue reading on narkive:
Loading...