user291071
user291071

Reputation: 351

google app engine ApplicationError: 2 nonnumeric port: ''

I am getting the ApplicationError: 2 nonnumeric port: '' randomly for about 1/10th of my url request, the rest work fine, I seen this is a bug but I have yet to find any solutions, anyone have any thoughts in why this is occurring? I am running python 2.5.4 and google app engine 1.3.3

here is some generic code the error is occuring when requesting pages randomly

def overview(page):
     try:
          page = "http://www.url.com%s.json?" %page
          u = urllib.urlopen(page.encode('utf-8'))
          bytes = StringIO(u.read())
          u.close()
     except Exception, e:
          print e
          return None
     try:
        JSON_data = json.load(bytes)
        return JSON_data
     except ValueError:
        print "Couldn't get .json for %s" % page
        return None  

Upvotes: 1

Views: 609

Answers (1)

Adam Crossland
Adam Crossland

Reputation: 14213

Couple of things with your code that could be problems. One is that you aren't doing anything with the incoming value of page, but it is being over-written by the assignment fort thing inside your try block. Also, as I noted in my comment, the %s in the assignment wants to have a variable to substitute in its place. That's probably what you are meant to to with the value coming in the page parameter. Try this:

def overview(page_to_get):
     try:
          page = "http://www.url.com%s.json?" % page_to_get
          u = urllib.urlopen(page.encode('utf-8'))
          bytes = StringIO(u.read())
          u.close()
     except Exception, e:
          print e
          return None
     try:
        JSON_data = json.load(bytes)
        return JSON_data
     except ValueError:
        print "Couldn't get .json for %s" % page
        return None 

EDIT:

@user291071: I would guess that some of that values that are coming in through overview's parameter page do not start with a leading slash. The only way to make sure that the URL parser doesn't try to interpret the added-on information as a port-number is to make sure that it starts with a / or a ?. perhaps this will work better for you:

          page = "http://www.url.com/%s.json?" % page_to_get

but it may cause other URLs that are currently working to fail. The best thing to do would be to log the URLs that are being created and visually inspect the ones that are failing.

Upvotes: 1

Related Questions