BadKeyError: Incorrect line input

I use a standard couple of lines of code to extract a key from an http get request and use it to get something from the data store, but I ran into a problem that I had not encountered before. This only happens in the live (deployed) version - there is no problem running the code on the dev server.

Code snippet:

imgId = self.request.args.get("img_id") imageInfo = db.get(imgId) 

And an example error:

  BadKeyError: Invalid string key ahFjeWJlcm5hdXRzcHJvamVjdHINCxIFSW1hZ2UY1oYDDA=. Details: Incorrect padding 

If I register the imgId value right before db.get, this is correct (without adding the "=" from the debug message). Does anyone know what could be causing this?

+4
source share
2 answers

I assume url encoding. try:

 imgId = urllib.unquote(self.request.args.get("img_id")) 

could there be spaces?
try:

 imgId = urllib.unquote(self.request.args.get("img_id")).strip() 
+7
source

If this is not a URL encoding, then perhaps it has something to do with the args variable.

If this is an HTTP GET request:

 imgId = self.request.GET.get("img_id") imageInfo = db.get(imgId) 

If this is an HTTP POST request:

 imgId = self.request.POST.get("img_id") imageInfo = db.get(imgId) 
0
source

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


All Articles