我在我的网站上使用python flask和pusher API进行实时消息传递。 一切都能在开发烧瓶服务器中按预期工作,但是当我切换到gunicorn和nginx实时服务器时,麻烦就开始了。 当我触发pusher事件时,出现错误500。 也许我必须在nginx.conf文件中配置一些内容?
/etc/nginx/sites-enabled/đir
server {
listen 80;
server_name 172.104.228.152;
location /static {
alias /home/marko/Đir/đir/static;
}
location / {
proxy_pass http://localhost:8000;
include /etc/nginx/proxy_params;
proxy_redirect off;
}
}.
这是错误消息:
[2020-02-03 17:00:25,938] ERROR in app: Exception on /objave [POST]
Traceback (most recent call last):
File "/home/marko/\udcc4\udc90ir/venv/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/home/marko/\udcc4\udc90ir/venv/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/marko/\udcc4\udc90ir/venv/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/marko/\udcc4\udc90ir/venv/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/marko/\udcc4\udc90ir/venv/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/home/marko/\udcc4\udc90ir/venv/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/marko/Đir/đir/rute.py", line 30, in dekorator
return f(*args, **kwargs)
File "/home/marko/Đir/đir/rute.py", line 143, in objave
pusher_client.trigger('objava-kanal', 'nova-objava', {'sport': objava.sport, 'mjesto': objava.mjesto, 'datum': datum, 'sat': sat, 'id': objava.id, 'broj': len(o> File "/home/marko/\udcc4\udc90ir/venv/lib/python3.7/site-packages/pusher/pusher.py", line 118, in trigger
channels, event_name, data, socket_id)
File "/home/marko/\udcc4\udc90ir/venv/lib/python3.7/site-packages/pusher/http.py", line 31, in __call__
return self.client.http.send_request(self.make_request(*args, **kwargs))
File "/home/marko/\udcc4\udc90ir/venv/lib/python3.7/site-packages/pusher/requests.py", line 44, in send_request
**self.options)
File "/home/marko/\udcc4\udc90ir/venv/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/home/marko/\udcc4\udc90ir/venv/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/home/marko/\udcc4\udc90ir/venv/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout File "/home/marko/\udcc4\udc90ir/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 672, in urlopen chunked=chunked,
File "/home/marko/\udcc4\udc90ir/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 376, in _make_request
self._validate_conn(conn)
File "/home/marko/\udcc4\udc90ir/venv/lib/python3.7/site-packages/urllib3/connectionpool.py", line 994, in _validate_conn
conn.connect()
File "/home/marko/\udcc4\udc90ir/venv/lib/python3.7/site-packages/urllib3/connection.py", line 394, in connect
ssl_context=context,
File "/home/marko/\udcc4\udc90ir/venv/lib/python3.7/site-packages/urllib3/util/ssl_.py", line 336, in ssl_wrap_socket
context.load_verify_locations(ca_certs, ca_cert_dir)
File "/home/marko/\udcc4\udc90ir/venv/lib/python3.7/site-packages/urllib3/contrib/pyopenssl.py", line 450, in load_verify_locations
cafile = cafile.encode("utf-8")
UnicodeEncodeError: 'utf-8' codec can't encode characters in position 12-13: surrogates not allowed
修改: 'routes.py'
pusher_client = pusher.Pusher(
app_id='930370',
key='43251c740e8c7fdc4747',
secret='6cc68633eec00ebf9b9d',
cluster='eu',
ssl=True
)
@app.route("/objave", methods=["GET", "POST"])
@potrebna_prijava
def objave():
#obrazac za novi događaj
obrazac = ObjavaObrazac()
#obrazac za filter događaja
_filter = Filter()
if obrazac.validate_on_submit():
datum = datetime.strptime(obrazac.datum.data, "%Y/%m/%d %H:%M")
objava = Objava(sport=obrazac.sport.data.capitalize(), mjesto=obrazac.mjesto.data.capitalize(), datum=datum, opis=obrazac.opis.data, korisnik_id=session["korisnik_id"])
db.session.add(objava)
db.session.commit()
datum = objava.datum.strftime("%a, %d.").capitalize()
sat = objava.datum.strftime("%H:%M")
#pusher trigger
pusher_client.trigger('objava-kanal', 'nova-objava', {'sport': objava.sport, 'mjesto': objava.mjesto, 'datum': datum, 'sat': sat, 'id': objava.id, 'broj': len(objava.sudionici)})
flash('Kreirano', 'dobro')
return redirect(url_for('objave'))
if _filter.validate_on_submit():
return redirect(url_for('objave', mjesto_filter=_filter.f_mjesto.data, sport_filter=_filter.f_sport.data))
objave = selektiraj()
#slika korisnika
avatar = Korisnik.query.get(session.get("korisnik_id")).avatar
return render_template("objave.html", obrazac=obrazac, objave=objave, avatar=avatar, filter=_filter)
P.S。 翻译:objava =帖子,objave =帖子,obrazac =表格
答案 0 :(得分:1)
我设法通过设置pusher ssl = False解决了这个问题。 这真是一个奇怪的解决方案,在文档或错误日志中都不会令人难过。