[Tutor] Problem

Alan Gauld alan.gauld at btinternet.com
Sat Dec 27 02:15:49 CET 2014


On 26/12/14 16:16, salisme salisme wrote:

> I am having a big problem trying to open a url that
 > I have created by concatenating a raw_input
 > on to an already existing url.

Thats not what your code says beloiw. Although its kind
of hard to read since you didn't post in plain text...

But you appear to be using input() not raw_input().
If its Python3 it should be input() but if its Python2
that will likely do something very different.

> When I copy and paste the url in to the search bar it works

Which url? Have you compared it with the baseurl value below?
Did you cut n paste the baseurl value into the search bar? Or did you 
type what you thought it should be?

> fine but when I try to open it using urllib.request.urlopen(url)
 > it givesme a 505 HTTP error.

How do you see this error? Is it printed on screen? in a log file?
Do you get any Python errors. Please show us a cut n' paste of
the actual error text.

> import reimport urllibfrom urllib.request import urlparsefrom urllib.request import urlopenfrom urllib.request import urlretrievefrom bs4 import BeautifulSoup as bs
> choice = input("Choose artist and album name in following format : Artist 'x' album 'y'")
> baseurl = "http://www.ebay.co.uk/sch/Records-/176985/i.html?_nkw=" + choice + '&_pgn=1'
> then I get an error from the following:
> urllib.request.urlopen(baseurl) 		 	   		

What are you doing with the return value of urlopen()?
Are you really thropwing it away?

Please post, in plain text, the actual Python code that
produces the error and the error message. And tell us
which Python version and OS you are using.

That way we might be able to help.


-- 
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




More information about the Tutor mailing list