473,406 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

how to check the 'content/type' using urlopen


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

Apr 15 '07 #1
2 2243

On Apr 15, 2007, at 6:25 PM, John wrote:
>
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
---
Asking a person who he *is* ... is not Pythonic! --Anton Vredegoor


Apr 16 '07 #2
Michael Bentley <mi*****@jedimindworks.comwrites:
On Apr 15, 2007, at 6:25 PM, John wrote:

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.
handle.get_header("Content-type")
John
Apr 16 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Phillip | last post by:
Some people tipped me off on some possibilities to tackle my https problem. Those have definitely gotten me further in cornering the problem. Thank you. But: No matter what I do to open a...
2
by: Justin | last post by:
I have a program that downloads files from the web. There are instances in which a .info() will not return a "Content-length" header to me. Is ther a way to specifically request this header or...
2
by: john | last post by:
Im new to python. So I was hoping someone could provide the following. How would I go about checking if a user can be opened. For example if user provides www.x.com, how would I check if there is...
0
by: Matt | last post by:
I'm trying to get the HTML data off of a webpage. Let's say for the sake of argument it's the python homepage. I've googled around and found some examples that people said worked. Here's what...
0
by: Pieter Edelman | last post by:
Hi all, I'm trying to submit some data using a POST request to a HTTP server with BASIC authentication with python, but I can't get it to work. Since it's driving me completely nuts, so here's...
11
by: Johnny Lee | last post by:
Hi, I was using urllib to grab urls from web. here is the work flow of my program: 1. Get base url and max number of urls from user 2. Call filter to validate the base url 3. Read the source...
4
by: VR | last post by:
I am trying to embed a check box into a FlexGrid's cell, but having a problem when I start scrolling the grid. Here is my MyCheckBox class... class MyCheckBox : CheckBox { void Init (...
3
by: TK | last post by:
Excuse me for multiple posting because I've posted this message to aspnet.security NG but have not got any response yet. I'm building an ASP.NET application works in Forms Authentication mode...
0
by: philip20060308 | last post by:
Hi all, Has anyone ever seen Python 2.4.1's httplib choke when reading chunked content? I'm using it via urrlib2, and I ran into a particular server that returns something that httplib doesn't...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.