http access produces 503

Piet van Oostrum piet at cs.uu.nl
Wed Aug 5 22:14:04 CEST 2009


>>>>> Rog <af1ing at seznam.cz> (R) wrote:

>R> I am porting a simple code from Perl, the website asks for usr/pwd and
>R> the server's side Perl script makes atemp ftp dir for file upload.

>R> The original Perl script connects okay, does its job. The same URL
>R> stuffed into FF3 performs the same way.
>R> My Python script I am sweating out for past four days (noob!) gets
>R> consistently "503", even with user agen set to: Mozilla/5.0 (Windows;
>R> U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11.
>R> Snippets of relevant code below.

>R> Please, help me understand how this same code lets me log in into my
>R> router usr/pwd running .asp, but this !@#$% perl script returns to me
>R> w/503 c*ap?
>R> Thank you.

Which perl script?

>R> Do I need to set any proxy? The server is on intranet and the FF3 is
>R> set to proxy. The original Perl script did not use any proxy setting.

>R> <pre>

>R> url = http://example.com/ftpsetup.pl?username=boofa&nodeid=42
>R> #########################################################
>R> # create a password manager
>R>     password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
>R> # Add the username and password.
>R> # If we knew the realm, we could use it instead of ``None``.
>R>     password_mgr.add_password(None, url, uid, pcode)
>R>     handler = urllib2.HTTPBasicAuthHandler(password_mgr)
>R>     class Mopener(URLopener): version = "Mozilla/5.0 (Windows; U;
>R> Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11"

>R>     opener = Mopener()

>R> # create "opener" (OpenerDirector instance)

>R>     opener = urllib2.build_opener(handler)
>R>     opener.addheaders = [('User-agent', 'Mozilla/5.0 (Windows; U;
>R> Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11')]

>R>     opener.version = "Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:
>R> 1.8.1.11) Gecko/20071127 Firefox/2.0.0.11"

>R>     print opener.version
>R> # timeout in seconds
>R>     timeout = 10
>R>     socket.setdefaulttimeout(timeout)

>R> # Install the opener all calls to urllib2.urlopen use our opener.
>R>     urllib2.install_opener(opener)

>R>     try:
>R>         response = opener.open(url)
>R>         # "http://www.useragent.org/" tested okay!!!
>R>         print"ok = 1"
>R>     except:
>R>         print "error 1"
>R> #####################################################################################

This code is a mess. The indentation is wrong so it can't be your real
code. Imports are missing. And there is a lot of garbage that doen't do
anything. E.g. The Mopener business is not used. install_opener is not
used.

Please make a minimal examples and check if that fails to. Like:

import urllib2
import socket

url = 'http://example.com/ftpsetup.pl?username=boofa&nodeid=42'
uid = ...
pcode = ...

# create a password manager
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
# Add the username and password.
# If we knew the realm, we could use it instead of ``None``.
password_mgr.add_password(None, url, uid, pcode)
handler = urllib2.HTTPBasicAuthHandler(password_mgr)

# create "opener" (OpenerDirector instance)
opener = urllib2.build_opener(handler)

# timeout in seconds
timeout = 10
socket.setdefaulttimeout(timeout)

try:
    response = opener.open(url)
    print response.read()
    print"ok = 1"
except:
    print "error 1"



>R> output from the above:

>R> Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/
>R> 20071127 Firefox/2.0.0.11
>R> error 1
>R> Error code:  503
>R> ('Service Unavailable', 'The server cannot process the request due to
>R> a high load')

That suggests that there is a real problem in the server. Or that your
url causes some problems.

-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org



More information about the Python-list mailing list