I have the following code to load a url (address).
When I have a url like this, http://www.testcom.co.uk/dev_12345/www.cnn.com
i get an error "Failed to open http://www.testcom.co. uk/dev_12345/www.cnn.com".
Is there something wrong with my URL? or something wrong with my code?
Thank you for any help.
cj = cookielib.LWPCo okieJar()
opener = urllib2.build_o pener(urllib2.H TTPCookieProces sor(cj))
urllib2.install _opener(opener)
txheaders = {'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5;
Windows NT)'}
try:
print "address", address
print "txdata", txdata
print "txheaders" , txheaders
req = Request(address , txdata, txheaders)
handle = urlopen(req)
except IOError, e:
print address
print 'Failed to open %s' % address
data = "" 1 1371
On Mar 31, 7:21 am, "ying...@gmail. com" <ying...@gmail. comwrote:
I have the following code to load a url (address).
When I have a url like this,
http://www.testcom.co.uk/dev_12345/www.cnn.com
i get an error "Failed to openhttp://www.testcom.co. uk/dev_12345/www.cnn.com".
Is there something wrong with my URL? or something wrong with my code?
With the URL.
See http://www.dnsstuff.com/tools/dnsrep....testcom.co.uk
Thank you for any help.
cj = cookielib.LWPCo okieJar()
opener = urllib2.build_o pener(urllib2.H TTPCookieProces sor(cj))
urllib2.install _opener(opener)
txheaders = {'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5;
Windows NT)'}
try:
print "address", address
print "txdata", txdata
print "txheaders" , txheaders
req = Request(address , txdata, txheaders)
handle = urlopen(req)
I suppose you've added the appropriate imports for Request and
urlopen.
except IOError, e:
print address
print 'Failed to open %s' % address
data = ""
--
Kushal This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Andre Bocchini |
last post by:
I'm having some trouble using proxy authentication. I can't figure out
how to authenticate with a Squid proxy. I know for a fact the proxy is
using Basic instead of Digest for the authentication. I can
authenticate just fine using Mozilla. I've done some Google searches,
but the closest piece of code I've is is for HTTPBasicAuthHandler:
# set up authentication info
authinfo = urllib2.HTTPBasicAuthHandler()...
|
by: bmiras |
last post by:
I've got a problem using urllib2 to get a web page.
I'm going through a proxy using user/password authentification
and i'm trying to get a page asking for a HTTP authentification.
And I'm using python 2.3
Here is an exemple of the piece of code I use:
import urllib2
#Proxy handler
proxy_handler = urllib2.ProxyHandler({"http" :
|
by: John F Dutcher |
last post by:
Can anyone comment on why the code shown in the Python error is in
some way incorrect...or is there a problem with Python on my hoster's
site ??
The highlites don't seem to show here...but line #80 and line # 38 are
the first line offenders.
--> --> -->
|
by: jacob c. |
last post by:
When I request a URL using urllib2, it appears that urllib2 always
makes the request using HTTP 1.0, and not HTTP 1.1. I'm trying to use
the "If-None-Match"/"ETag" HTTP headers to conserve bandwidth, but if
I'm not mistaken, these are HTTP 1.1 headers, so I can't reasonably
expect a web server to respond correctly to my requests. (In my
limited testing, it looks like some servers respond correctly with an
HTTP 304 status, while some...
|
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: Phoe6 |
last post by:
Hi All,
I am able to use urlib2 through proxy. I give proxy credentials and use
# Set the Proxy Address
proxy_ip = "10.0.1.1:80"
proxy_user = 'senthil_or'
proxy_password_orig='password'
|
by: Jack |
last post by:
I'm trying to use a proxy server with urllib2.
So I have managed to get it to work by setting the environment
variable:
export HTTP_PROXY=127.0.0.1:8081
But I wanted to set it from the code. However, this does not set the proxy:
httpproxy = '127.0.0.1:3129'
proxy_support = urllib2.ProxyHandler({"http":"http://" + httpproxy})
opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler)
urllib2.install_opener(opener)
|
by: Alexnb |
last post by:
Okay, I tried to follow that, and it is kinda hard. But since you obviously
know what you are doing, where did you learn this? Or where can I learn
this?
Maric Michaud wrote:
class=r>.*?</h2>',
--
View this message in context: http://www.nabble.com/using-urllib2-tp18150669p18160312.html
|
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: 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: 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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
| |