how to check the 'content/type' using urlopen

J

John

i have the following code to open a URL address, but can you please
tell me how can I check the content type of the url response?

Thank you.

try:
req = Request(url, txdata, txheaders)
handle = urlopen(req)
except IOError, e:
print e
print 'Failed to open %s' % url
return 0;

else:
data = handle.read()
 
M

Michael Bentley

i have the following code to open a URL address, but can you please
tell me how can I check the content type of the url response?

Thank you.

try:
req = Request(url, txdata, txheaders)
handle = urlopen(req)
except IOError, e:
print e
print 'Failed to open %s' % url
return 0;

else:
data = handle.read()

Not absolutely sure about this, but try handle.headers.get('Content-
Type') before the read.

hth,
Michael
 
J

John J. Lee

Michael Bentley said:
Not absolutely sure about this, but try handle.headers.get('Content-
Type') before the read.

handle.get_header("Content-type")


John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top