Websocket error in my consumers

but you have seen well there is no difference of version :frowning:

Uh, yea, there are. Quite a number of, actually.

if I delete all the packages and reinstall them version by version, do you think it’s a good idea?

First, you don’t need to delete packages yourself. Pip will properly install a different version of a package by uninstalling the original package first.

Given that most of the version differences I see show your production server as having newer versions of libraries than your local environment, you need to make a choice. You need to decide what your ultimate objective is.

If you consider this project to be a “dead-end” effort, you may just want to find the quickest answer and move on.

However, if this is something you’re looking to keep around for a while, you may want to spend the time now to understand what is going wrong.

I would suggest:

  • Identify which libraries you have installed in production that are a different version than what you have installed locally.

  • Identify which of those libraries are being used (directly and indirectly to the best that you know) in your Consumer.

  • Try to order that list in order of “reliability”, check the more “questionable” third-party libraries first. (Yes, that’s very much a judgement call.)

  • If you’re using a virtual environment for your project, use pip to install the same specific version of those libraries as what you have installed in your local environment.

    • If you do this one-by-one, one library at a time, you can identify which library is causing the problem.
  • If you’re using the system-level Python environment for your project (not a good choice, but it can be done), I’d recommend switching to using a virtual environment.

or

You could do a pip freeze of your local environment to make a requirements file replicating your local environment and use pip install of that file in your production server.

or

You might want to create another virtual environment locally with the versions of the packages that are installed in production to see if you get the same errors in your local environment.

idiot that I am, I was updating my packet guy outside the virtual environment, so I updated but I have this little error that appeared

# ImportError at /

cannot import name 'Random' from 'django.db.models.expressions' (/home/wahab/apporder/env/lib/python3.10/site-packages/django/db/models/expressions.py)

|Request Method:|GET|
| --- | --- |
|Request URL:|http://*****/|
|Django Version:|3.2|
|Exception Type:|ImportError|
|Exception Value:|cannot import name 'Random' from 'django.db.models.expressions' (/home/wahab/apporder/env/lib/python3.10/site-packages/django/db/models/expressions.py)|
|Exception Location:|/home/wahab/apporder/env/lib/python3.10/site-packages/django/db/models/sql/compiler.py, line 9, in <module>|
|Python Executable:|/home/wahab/apporder/env/bin/python|
|Python Version:|3.10.6|
|Python Path:|['/home/wahab/apporder', '/home/wahab/apporder/env/bin', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '/home/wahab/apporder/env/lib/python3.10/site-packages']|
|Server time:|Sat, 19 Nov 2022 17:10:33 +0000|

and a little further down this error

* ### During handling of the above exception ('SessionStore' object has no attribute '_session_cache'), another exception occurred:

but out of my virtual environment I have installed the same packets, should I delete them?

No, you should fix your import statement.

but I never import random

Ah, I see now. What is the full version number of Django that you are using?

i use Django==3.1 in local and in prod

Please read: Django 3.1 release notes | Django documentation | Django

but wait there is a problem, it is written on the error that I use django 3.2

I have restarted everything and I don’t have the error anymore, but there is still this webcoket problem, are you sure that it is not necessary to uninstall the packages that are not in the env?

Absolutely not an issue to have extra packages that aren’t being used.

Does the fact that I use 3.10.8 locally and 3.10.6 in production change anything?

Referring to Python? I couldn’t say. While my inclination is that that doesn’t matter, I don’t know that for sure. I’m not specifically aware of the differences between those two versions.

I have the impression that it is not the content, but that there is a problem with the consumers.py, is it compulsory that the consumer is in consumers.py, I can maybe try to move it in my views to see if the error persists?

@KenWhitesell After spending an hour checking and installing each package 1 by 1, go to the page I send you

on the left the packages in the production env
on the right the packages in local

Not that I am aware of. From what I see, the only reference to that file is in the routing.py file, which itself is referenced by the asgi.py file, which is provided to daphne/uvicorn.

As long as the references are good, the name of the file shouldn’t matter.

Ok, I’ve looked at it. What am I looking for?

There are no version differences for the packages

1 Like