简体   繁体   中英

Flask SSL receiving garbage requests

I've got a basic Flask server setup with some endpoints. I'm trying to test this out using curl (I've tried both from localhost and remotely, the result is the same).

If I curl the path over http, it works great. If I do it over https, the request looks like garbage (see below) and curl returns "curl: (35) gnutls_handshake() failed: An unexpected TLS packet was received."

Requests received over https typically looks similar to:

136.152.142.32 - - [16/Nov/2017 01:32:56] code 400, message Bad request syntax ('\x16\x03\x01\x00\xe3\x01\x00\x00\xdf\x03\x03Z\x0c\xea\xcf\rG\x12,\xea}\xc4\x17n\xb7\x0c\x0b\xea\xdbM\x87n\xf3\x95\xa7(\x15+\xb5lyzY\x00\x00n\x00\xff\xc0,\xc0+\xc0$\xc0#\xc0')
136.152.142.32 - - [16/Nov/2017 01:32:56] "??Z
G,?}?n?           

                        ??

I added SSL functionality by simply adding an ssl_context to my flask app.

if __name__ == '__main__':
    context = ('fullcert.pem', 'privkey.pem')
    app.run(debug=False, ssl_context=context)

The keys are signed by a CA and worked fine in a comparable node application (I'm trying to convert that node application over to python/flask).

I've tried basically reinstalling from the ground up with no success.

This is being hosted on DigitalOcean in case anyone knows of some weird default configuration that they do that could be causing this. I've specifically opened the port that the application is running on.

Does anyone have any other suggestions of what could be causing the problem?

I'm going to go ahead and chalk this up to some kind of problem with the Flask dev server. I deployed my application using the exact same code with Apache (specifically, I followed this handy guide: https://www.digitalocean.com/community/tutorials/how-to-deploy-a-flask-application-on-an-ubuntu-vps ) and it worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM