Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > http access produces 503

Reply
Thread Tools

http access produces 503

 
 
Rog
Guest
Posts: n/a
 
      08-05-2009
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>
 
Reply With Quote
 
 
 
 
Piet van Oostrum
Guest
Posts: n/a
 
      08-05-2009
>>>>> Rog <(E-Mail Removed)> (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 <(E-Mail Removed)>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
return HttpStatusCode.ServiceUnavailable in the context.context.Response.StatusCode (Http response code 503) Flip Rayner ASP .Net 1 01-23-2007 06:35 AM
OutputStream from a URLConnection produces an OutOfMemory OutputStream from a URLConnection produces an OutOfMemory WinstonSmith_101@hotmail.com Java 2 10-25-2006 04:45 PM
HTTP Status 503 - Servlet action is currently unavailable... help me? Pasha Java 2 05-12-2006 06:39 AM
Please give solution for this : HTTP/1.0 503 Service Unavailable harinath ASP .Net 0 02-07-2006 11:49 AM
ERROR: 'HTTP/1.0 503 Service Unavailable' =?Utf-8?B?VG9tYXMgS2VwaWM=?= ASP .Net 11 04-05-2005 04:39 PM



Advertisments