Python Forum
missing 1 required positional argument error - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: missing 1 required positional argument error (/thread-16396.html)



missing 1 required positional argument error - nikos - Feb-26-2019

I'm receiving the following error:

Error:
Traceback (most recent call last): File "/usr/lib64/python3.6/site-packages/bottle.py", line 862, in _handle return route.call(**args) File "/usr/lib64/python3.6/site-packages/bottle.py", line 1740, in wrapper rv = callback(*a, **ka) File "/usr/lib64/python3.6/site-packages/bottle.py", line 2690, in wrapper return func(*a, **ka) TypeError: listall() missing 1 required positional argument: 'pymydb'
and this is my route:
@app.route( '/' )
@auth_basic(counters.is_authenticated_user)
def listall( pymydb ):
The way i understand this error is that i'am trying to call 'listall()' without giving it an argument while in its definition i do have 'pymydb' as a parameter.

BUT from inside my script i do NOT call listall at all, so how can it miss an argument?


RE: missing 1 required positional argument error - stranac - Feb-26-2019

Where is pymydb supposed to come from?
I'm not super-familiar with bottle, but in most frameworks which use route decorators, arguments are provided by the decorator when using an appropriately-formatted route path.


RE: missing 1 required positional argument error - nikos - Feb-26-2019

pymydb comes from these lines in the top of myscript.

plugin = bottle_pymysql.Plugin( dbuser='nikos', dbpass='trustno1bm3$', dbname='clientele', dictrows=False )
app.install(plugin)
That is in the top of my script after the imports and NOT within the view function in case it matters.

i have 2 scripts with '/' routes and they both use the parameter 'pymydb'

@app.route( '/' ) 
@app.route( '/<page>' ) 
def index( pymydb, page='index.html' ):
this one works without an error, so it seems it can find pymydb

while in my other script

@app.route( '/' )
@auth_basic(counters.is_authenticated_user)
def listall( pymydb ):
is giving the error i posted.

i just noticed that if i remove the:

@auth_basic(counters.is_authenticated_user)
then the script work without giving me an error!

But why is that?


RE: missing 1 required positional argument error - nikos - Feb-28-2019

Hello, can someone help me with this please?

This route works as expected

@app.route( '/download', method=['GET', 'POST'] )
def download( pymydb ):
while the following, in which iam trying with http auth

@app.route( '/download', method=['GET', 'POST'] )
@auth_basic(counters.is_authenticated_user)
def download( pymydb ):
fails by giving me the error

Error:
TypeError("download() missing 1 required positional argument: 'pymydb'",) Traceback: Traceback (most recent call last): File "/usr/lib64/python3.6/site-packages/bottle.py", line 862, in _handle return route.call(**args) File "/usr/lib64/python3.6/site-packages/bottle.py", line 1740, in wrapper rv = callback(*a, **ka) File "/usr/lib64/python3.6/site-packages/bottle.py", line 2690, in wrapper return func(*a, **ka) TypeError: download() missing 1 required positional argument: 'pymydb'
Why is that? How will i be able to enable http auth in this route?