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() 2 2273
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
Michael Bentley <mi*****@jedimi ndworks.comwrit es:
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_head er("Content-type")
John This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 webconnection with httpS I always get
something in this Area:
urllib2.URLError: <urlopen error unknown url type: https>
|
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 FORCE it
to be sent? I know there is some way to get the file size for these
files because Internet Explorer is capable of determining the size on a
cut / paste of the same exact url.
|
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 such a url?
What methods would I need to invoke?
Thank you very much for your time
|
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 I've cobbled
together:
#getHTML.py
############################################
import urllib
import urllib2
proxy_info = {'user':'us3r',
|
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 my cry for help.
The server is an elog logbook server (http://midas.psi.ch/elog/). It is
protected with a password and an empty username. I can login both using
urllib and urllib2 (suppose the password is "foobar", the logbook is
running on port...
| |
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 of the base url and grab all the urls from "href"
property of "a" tag
4. Call filter to validate every url grabbed
5. Continue 3-4 until the number of url grabbed gets the limit
|
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
(
AxMSFlexGridLib.AxMSFlexGrid oGrid,
|
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 with
custom user account database. And it shows clients a list of hyperlinks to
content pages located in some separated subfolders. This application and
content pages are entirely secured, so everyone must logon to the
application. The application...
|
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 expect. Specifically, in
the code below where the error occurs, line == ''.
Python 2.4.1 (#2, Oct 12 2005, 01:36:32)
20050518] on freebsd6
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib2
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |