http access produces 503

Discussion in 'Python' started by Rog, Aug 5, 2009.

  1. Rog

    Rog Guest

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

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

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

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

    <pre>

    url = http://example.com/ftpsetup.pl?username=boofa&nodeid=42
    #########################################################
    # 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)
    class Mopener(URLopener): version = "Mozilla/5.0 (Windows; U;
    Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11"

    opener = Mopener()

    # create "opener" (OpenerDirector instance)

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

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

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

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

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

    output from the above:

    Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/
    20071127 Firefox/2.0.0.11
    error 1
    Error code: 503
    ('Service Unavailable', 'The server cannot process the request due to
    a high load')
    </pre>
     
    Rog, Aug 5, 2009
    #1
    1. Advertising

  2. >>>>> Rog <> (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 <>
    URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
    Private email:
     
    Piet van Oostrum, Aug 5, 2009
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VG9tYXMgS2VwaWM=?=

    ERROR: 'HTTP/1.0 503 Service Unavailable'

    =?Utf-8?B?VG9tYXMgS2VwaWM=?=, Apr 2, 2005, in forum: ASP .Net
    Replies:
    11
    Views:
    13,809
    =?Utf-8?B?VG9tYXMgS2VwaWM=?=
    Apr 5, 2005
  2. harinath
    Replies:
    0
    Views:
    3,665
    harinath
    Feb 7, 2006
  3. Pasha
    Replies:
    2
    Views:
    13,719
  4. Dilip
    Replies:
    1
    Views:
    392
    Dilip
    Jul 18, 2003
  5. BuddyWork

    HTTP Status-Code=503 (Service Unavailable)

    BuddyWork, May 4, 2005, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    203
    BuddyWork
    May 4, 2005
Loading...

Share This Page