miguelgrinberg / flask-sock

Modern WebSocket support for Flask.
MIT License
274 stars 24 forks source link

The Error "TypeError: __init__() got an unexpected keyword argument 'websocket'" is confusing #3

Closed lancezhaozai closed 3 years ago

lancezhaozai commented 3 years ago

Like title, the error

"TypeError: init() got an unexpected keyword argument 'websocket'"

will prompt up out of random, i checked its not my code syntax error or what not, because when i restart my server, its worked again

Here is the stack trace after i ran 'flask run --host=0.0.0.0'

` * Serving Flask app "./run.py"

if try to simulate this error, it would not generate, this appear out of random

miguelgrinberg commented 3 years ago

When you report an error, please include the stack trace.

lancezhaozai commented 3 years ago

When you report an error, please include the stack trace.

ok, i had editted the post

miguelgrinberg commented 3 years ago

Can you share the output of pip freeze?

lancezhaozai commented 3 years ago

Can you share the output of pip freeze?

Here is the pip3 freeze output:

attrs==19.3.0 Automat==0.8.0 blinker==1.4 boto3==1.17.62 botocore==1.20.62 certifi==2019.11.28 chardet==3.0.4 Click==7.0 cloud-init==20.2 colorama==0.4.3 command-not-found==0.3 configobj==5.0.6 constantly==15.1.0 cryptography==2.8 dbus-python==1.2.16 distro==1.4.0 distro-info===0.23ubuntu1 ec2-hibinit-agent==1.0.0 entrypoints==0.3 Flask==1.1.2 Flask-Login==0.5.0 flask-sock==0.3.0 Flask-SQLAlchemy==2.5.1 Flask-WTF==0.14.3 greenlet==1.1.0 gunicorn==20.1.0 h11==0.12.0 hibagent==1.0.1 httplib2==0.14.0 hyperlink==19.0.0 idna==2.8 importlib-metadata==1.5.0 incremental==16.10.1 itsdangerous==1.1.0 Jinja2==2.11.3 jmespath==0.10.0 jsonpatch==1.22 jsonpointer==2.0 jsonschema==3.2.0 keyring==18.0.1 language-selector==0.1 launchpadlib==1.10.13 lazr.restfulclient==0.14.2 lazr.uri==1.0.3 mariadb==1.0.6 MarkupSafe==1.1.0 more-itertools==4.2.0 netifaces==0.10.4 oauthlib==3.1.0 Pillow==8.2.0 pyasn1==0.4.2 pyasn1-modules==0.2.1 PyGObject==3.36.0 PyHamcrest==1.9.0 pyinotify==0.9.6 PyJWT==1.7.1 pymacaroons==0.13.0 PyNaCl==1.3.0 pyOpenSSL==19.0.0 pyrsistent==0.15.5 pyserial==3.4 python-apt==2.0.0 python-dateutil==2.8.1 python-debian===0.1.36ubuntu1 PyYAML==5.3.1 requests==2.22.0 requests-unixsocket==0.2.0 s3transfer==0.4.2 SecretStorage==2.3.1 service-identity==18.1.0 simple-websocket==0.1.0 simplejson==3.16.0 six==1.14.0 SQLAlchemy==1.4.15 ssh-import-id==5.10 systemd-python==234 Twisted==18.9.0 ubuntu-advantage-tools==20.3 ufw==0.36 unattended-upgrades==0.1 urllib3==1.25.8 wadllib==1.3.3 websockets==9.0.1 Werkzeug==2.0.0 wsproto==1.0.0 WTForms==2.3.3 zipp==1.0.0 zope.interface==4.7.1

miguelgrinberg commented 3 years ago

I'm going to have to ask you to provide the code. I think this is, in fact, something that you are doing wrong in your application. Can you condense your code down to something small that you can share?

lancezhaozai commented 3 years ago

I'm going to have to ask you to provide the code. I think this is, in fact, something that you are doing wrong in your application. Can you condense your code down to something small that you can share?

Sure, but this code works fine, I mentioned the errors are prompting randomly

Following is my code run.py:

 app = create_app()

 if __name__ == '__main__':
    app.run(debug=True)`

And init.py:

from flask_sock import Sock

sock = None

def create_app(config_class=Config):

    global app, sock
    app = Flask(__name__)

    sock = Sock(app)

    import f3portal.socket.api

    return app

At last, the api.py:

from f3portal import sock

@sock.route('/state')
def state(ws):
    print("At Websocket...")

    # ws.close()
    # print(ws.connected)
    while ws.connected:
        text = ws.receive()

        print(text)

        ws.send(text)

    return ws.connected
miguelgrinberg commented 3 years ago

I'm going to make two suggestions:

First, upgrade Flask to version 2, or downgrade Werkzeug to the latest version 1.x.

If that does not help, then also trash your virtualenv and regenerate it from scratch. Hopefully this will take care of the problem.

lancezhaozai commented 3 years ago

I'm going to make two suggestions:

First, upgrade Flask to version 2, or downgrade Werkzeug to the latest version 1.x.

If that does not help, then also trash your virtualenv and regenerate it from scratch. Hopefully this will take care of the problem.

alright i will give a try on upgrading flask or downgrading werkzeug, but the errors are not appear regularly thus its not considering closed case if nothing happens

btw trashing the virtualenv and recreate another, i did tried before, its not helping

miguelgrinberg commented 3 years ago

btw trashing the virtualenv and recreate another, i did tried before, its not helping

@lancezhaozai you have an inconsistent set of dependencies, that was my first item that you needed to resolve before you regenerate your venv.

lancezhaozai commented 3 years ago

btw trashing the virtualenv and recreate another, i did tried before, its not helping

@lancezhaozai you have an inconsistent set of dependencies, that was my first item that you needed to resolve before you regenerate your venv.

hi sir, i resolved the issue adding following setting to gunicorn during startup

here is my startup conf:

gunicorn --worker-class=gevent --worker-connections=1000 --workers=5 --threads=1000 run:app --timeout 60 --graceful-timeout 60 --log-level=debug

few days i changed my direction to gunicorn issue, it seems insufficient workers and threads to manage the websocket connection

likhithpindi1 commented 1 year ago

from flask import *

app = Flask(name)

@app.route('/home', method= ['GET','POST']) def home(): First_Name = request.form['firstname'] if request.method == 'post': return ' HELLO %s'%First_Name else: return 'erroe'

if name == 'main': app.run(debug = True)


need help getting error : Exception has occurred: TypeError Rule.init() got an unexpected keyword argument 'method' File "D:\DBS\python_main\Integration_HTML\myproject\venv\demo.py", line 7, in def home():

miguelgrinberg commented 1 year ago

@likhithpindi1 this is a discussion board for Flask-Sock questions.