Python run.py unexpected keyword argument error

Hello,
I checked multiple threads about the run.py error, but couldn’t find the related question.
I am running this application on mac and I renamed dotini_unix to .ini file.
With run.py I am able to load the flask dev server but it is unable to fetch movies. I have updated the .ini file with the DB uri for M220P project. I am getting following error. I am not supplying any argument but still this ‘lifetime’ argument is getting passed.
(mflix) MacBook-Pro:mflix-python deepali$ python3 run.py
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with fsevents reloader
* Debugger is active!
* Debugger PIN: 323-884-071
127.0.0.1 - - [27/Aug/2021 17:10:16] “GET / HTTP/1.1” 200 -
127.0.0.1 - - [27/Aug/2021 17:10:16] “GET /api/v1/movies/ HTTP/1.1” 500 -
Traceback (most recent call last):
File “/opt/anaconda3/lib/python3.7/site-packages/pymongo/srv_resolver.py”, line 89, in _resolve_uri
lifetime=self.__connect_timeout)
File “/opt/anaconda3/lib/python3.7/site-packages/pymongo/srv_resolver.py”, line 48, in _resolve
return resolver.query(*args, **kwargs)
TypeError: query() got an unexpected keyword argument ‘lifetime’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/anaconda3/lib/python3.7/site-packages/flask/app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
  File "/opt/anaconda3/lib/python3.7/site-packages/flask/app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
  File "/opt/anaconda3/lib/python3.7/site-packages/flask_cors/extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/opt/anaconda3/lib/python3.7/site-packages/flask/app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
  File "/opt/anaconda3/lib/python3.7/site-packages/flask/_compat.py", line 33, in reraise
raise value
  File "/opt/anaconda3/lib/python3.7/site-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
  File "/opt/anaconda3/lib/python3.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
  File "/opt/anaconda3/lib/python3.7/site-packages/flask_cors/extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/opt/anaconda3/lib/python3.7/site-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
  File "/opt/anaconda3/lib/python3.7/site-packages/flask/_compat.py", line 33, in reraise
raise value
  File "/opt/anaconda3/lib/python3.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
  File "/opt/anaconda3/lib/python3.7/site-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/deepali/Desktop/Personal/mflix-python/mflix/api/movies.py", line 26, in api_get_movies
None, page=0, movies_per_page=MOVIES_PER_PAGE)
  File "/Users/deepali/Desktop/Personal/mflix-python/mflix/db.py", line 220, in get_movies
cursor = db.movies.find(query).sort(sort)
  File "/opt/anaconda3/lib/python3.7/site-packages/werkzeug/local.py", line 348, in __getattr__
return getattr(self._get_current_object(), name)
  File "/opt/anaconda3/lib/python3.7/site-packages/werkzeug/local.py", line 307, in _get_current_object
return self.__local()
  File "/Users/deepali/Desktop/Personal/mflix-python/mflix/db.py", line 47, in get_db
MFLIX_DB_URI,
  File "/opt/anaconda3/lib/python3.7/site-packages/pymongo/mongo_client.py", line 672, in __init__
connect_timeout=timeout)
  File "/opt/anaconda3/lib/python3.7/site-packages/pymongo/uri_parser.py", line 524, in parse_uri
nodes = dns_resolver.get_hosts()
  File "/opt/anaconda3/lib/python3.7/site-packages/pymongo/srv_resolver.py", line 118, in get_hosts
_, nodes = self._get_srv_response_and_hosts(True)
  File "/opt/anaconda3/lib/python3.7/site-packages/pymongo/srv_resolver.py", line 99, in _get_srv_response_and_hosts
results = self._resolve_uri(encapsulate_errors)
  File "/opt/anaconda3/lib/python3.7/site-packages/pymongo/srv_resolver.py", line 95, in _resolve_uri
raise ConfigurationError(str(exc))
pymongo.errors.ConfigurationError: query() got an unexpected keyword argument 'lifetime'
127.0.0.1 - - [27/Aug/2021 17:10:16] "GET /api/v1/movies/facet-search?cast=Denzel%20Washington&page=0 HTTP/1.1" 400 -
127.0.0.1 - - [27/Aug/2021 17:10:16] "GET /manifest.json HTTP/1.1" 200 -
127.0.0.1 - - [27/Aug/2021 17:10:16] "GET /favicon.ico HTTP/1.1" 200 -

Thank you in advance
Deepali

Thank you in advance

Hello! @Deepali_Rawool . This looks like the problem is dnspython package is out-of-date.
Could you please post your requirements.txt here?

Thank you,
Qang.

Hello,
Here is the file:

appnope==0.1.0
attrs==19.1.0
backcall==0.1.0
bcrypt==3.1.7
bleach==3.1.0
cffi==1.13.1
Click==7.0
decorator==4.4.0
defusedxml==0.6.0
dnspython==1.15.0
entrypoints==0.3
Faker==0.8.13
flake8==3.7.8
Flask==0.12.4
Flask-Bcrypt==0.7.1
Flask-Cors==3.0.3
Flask-JWT-Extended==3.7.0
Flask-Login==0.4.0
importlib-metadata==0.23
ipykernel==5.1.3
ipython==7.8.0
ipython-genutils==0.2.0
ipywidgets==7.5.1
itsdangerous==1.1.0
jedi==0.15.1
Jinja2==2.10.3
jsonschema==3.1.1
jupyter==1.0.0
jupyter-client==5.3.1
jupyter-console==6.0.0
jupyter-core==4.4.0
MarkupSafe==1.1.1
mccabe==0.6.1
mistune==0.8.4
more-itertools==7.2.0
nbconvert==5.6.0
nbformat==4.4.0
notebook==6.0.1
pandocfilters==1.4.2
parso==0.5.1
pexpect==4.7.0
pickleshare==0.7.5
pluggy==0.6.0
prometheus-client==0.7.1
prompt-toolkit==2.0.10
ptyprocess==0.6.0
py==1.8.0
pycodestyle==2.5.0
pycparser==2.19
pyflakes==2.1.1
Pygments==2.4.2
PyJWT==1.7.1
pymongo==3.7.2
pyrsistent==0.15.4
pytest==3.3.0
pytest-flask==0.11.0
python-dateutil==2.8.0
pyzmq==18.1.1
qtconsole==4.5.5
Send2Trash==1.5.0
six==1.12.0
terminado==0.8.2
testpath==0.4.2
text-unidecode==1.2
tornado==6.0.3
traitlets==4.3.3
wcwidth==0.1.7
webencodings==0.5.1
Werkzeug==0.16.0
widgetsnbextension==3.5.1
zipp==0.6.0

Thanks,
Deepali

Hello @Quang_Tran ,
Please find the attached requirement.txt
I have downloaded the application from the course page.

Thank you,
Deepali Rawool

Hello,
I recreated the virtual environment and then installed requirement.txt again.
And then it worked.

Thank you,
Deepali

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.