http access produces 503

R

Rog

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>
 
P

Piet van Oostrum

Rog said:
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> 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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top