ValueError: invalid literal for int () with base 10

When I tried to extract data using the Google App Engine, I received the following error: from one record to one page, for example. foobar.com/page/1 will display all data with ID 1:

ValueError: invalid literal for int() with base 10

Here are the files:

Views.py

class One(webapp.RequestHandler):    
    def get(self, id):
        id         = models.Page.get_by_id(int(str(self.request.get("id")))) 
        page_query = models.Page.get(db.Key.from_path('Page', id))
        pages      = page_query

        template_values = {
            'pages': pages,
        }

        path = os.path.join(os.path.dirname(__file__), 'template/list.html')
        self.response.out.write(template.render(path, template_values))

Urls.py

(r'/browse/(\d+)/', One),

Mistake:

Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/__init__.py", line 501, in __call__
    handler.get (* groups)
  File "/Volumes/foobar/views.py", line 72, in get
    id = models.Page.get_by_id (int (str (self.request.get ("id"))))
ValueError: invalid literal for int () with base 10: ''
+3
4

, . :

    id         = models.Page.get_by_id(int(str(self.request.get("id")))) 

, . , :

    id         = models.Page.get_by_id(int(id)) 

Odder - :

    page_query = models.Page.get(db.Key.from_path('Page', id))

- , 'id' 'int (id)', , . ?

+1

self.request.get("id") id, get.

, , URL-, /browse/1/?id=1

+2

. , int int(Decimal(str(self.request.get("id"))))

0

The error (since I'm sure you know - or should know that it seems you have made very far progress in programming) means that you are printing / reading the wrong literal (invalid character) for something that should have base 10 value (i.e., numbers 0-9).

0
source

Source: https://habr.com/ru/post/1714560/


All Articles