Pusher API not working on production server - python

I am using python flask, and pusher API for live messaging on my website.
Everything works as expected in development flask server, but the trouble starts when I switch to gunicorn and nginx live servers.
When I trigger pusher event I get an error 500.
Maybe I have to configure something in my nginx.conf file?
/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;
}
}.
This is the error message:
[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
Edit:
'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.
translations: objava = post, objave = posts, obrazac = form

I managed to solve this by setting pusher ssl = False.
It is really strange solution, nowhere to be sad in documentation or error log.

Related

TikTokApi throws an error in Flask but works outside of it

I have a strange problem when using flask + TikTok API that I can't figure out.
I have the following code:
from flask import Flask
from flask_restful import Resource, Api
from TikTokApi import TikTokApi
tikTokApi = TikTokApi()
app = Flask(__name__)
api = Api(app)
#app.errorhandler(404)
def page_not_found(e):
return {'status': 'fail'}, 404
class TikTokProfile(Resource):
def get(self):
profileResponse = tikTokApi.getUserObject('rosiethepygmygoat')
return {'user' : profileResponse}
class TikTokMedia(Resource):
def get(self):
data = tikTokApi.getUserObject('rosiethepygmygoat')
response = tikTokApi.userPage(data["id"],data["secUid"])
return response
api.add_resource(TikTokProfile, '/profile')
api.add_resource(TikTokMedia, '/media')
if __name__ == '__main__':
app.run(debug=True)
When I visit /profile I get the user object, but when I try to get his user page via the /media route I get the following error:
INFO:werkzeug:127.0.0.1 - - [08/Jan/2021 09:20:45] "GET /media HTTP/1.1" 500 -
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\flask\app.py", line 2464, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\flask\app.py", line 2450, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\flask_restful\__init__.py", line 272, in error_router
return original_handler(e)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\flask\app.py", line 1867, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\flask\_compat.py", line 38, in reraise
raise value.with_traceback(tb)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\flask\app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\flask_restful\__init__.py", line 272, in error_router
return original_handler(e)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\flask\app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\flask\_compat.py", line 38, in reraise
raise value.with_traceback(tb)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\flask\app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\flask_restful\__init__.py", line 468, in wrapper
resp = resource(*args, **kwargs)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\flask\views.py", line 89, in view
return self.dispatch_request(*args, **kwargs)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\flask_restful\__init__.py", line 583, in dispatch_request
resp = meth(*args, **kwargs)
File "D:\server\norway_group\tokmatic-sass\python\start.py", line 22, in get
response = tikTokApi.userPage(data["id"],data["secUid"])
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\TikTokApi\tiktok.py", line 562, in userPage
return self.getData(url=api_url, **kwargs)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\TikTokApi\tiktok.py", line 159, in getData
verify_fp, did, signature = self.browser.sign_url(**kwargs)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\TikTokApi\browser.py", line 164, in sign_url
page = self.create_page()
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\TikTokApi\browser.py", line 116, in create_page
context = self.browser.newContext(**iphone)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\playwright\sync_api.py", line 6710, in newContext
self._sync(
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\playwright\_sync_base.py", line 95, in _sync
self._dispatcher_fiber.switch()
greenlet.error: cannot switch to a different thread
I thought that there is an issue with the TikTokApi package but when I try the same code outside the flask resource:
data = tikTokApi.getUserObject('rosiethepygmygoat')
response = tikTokApi.userPage(data["id"],data["secUid"])
print(response)
I get the object I need.
So am I missing a specific configuration for flask or something else? Any insights will be much appreciated.
Run your flask application using this comands:
flask run --without-threads

Connect via py2neo to a neo4j with password secured http protocol

Hello I am trying to connect to a neo4j database with py2neo.
This code works so far:
graph = Graph(bolt=True, host='***',
bolt_port=***,
http_port=***,
user='***',
password='***')
But when I protect my IP address with a password over HTTP then I can't connect and I don't know how to authorize py2neo to connect.
Does anyone know how I can solve this? :)
Edit :
When I open the ip in a web browser i need to input a user and a password before i can see the neo4j browser - and I do not now how to input these credentias with py2neo (because it seems that this is my problem)
Stacktrace:
Traceback (most recent call last):
File "WebApp35\lib\site-packages\flask\app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "WebApp35\lib\site-packages\flask\app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "WebApp35\lib\site-packages\flask_restful\__init__.py", line 271, in error_router
return original_handler(e)
File "WebApp35\lib\site-packages\flask\app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "WebApp35\lib\site-packages\flask\_compat.py", line 32, in reraise
raise value.with_traceback(tb)
File "WebApp35\lib\site-packages\flask\app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "WebApp35\lib\site-packages\flask\app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "WebApp35\lib\site-packages\flask_restful\__init__.py", line 271, in error_router
return original_handler(e)
File "WebApp35\lib\site-packages\flask\app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "WebApp35\lib\site-packages\flask\_compat.py", line 32, in reraise
raise value.with_traceback(tb)
File "WebApp35\lib\site-packages\flask\app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "WebApp35\lib\site-packages\flask\app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "WebApp35\lib\site-packages\flask_restful\__init__.py", line 477, in wrapper
resp = resource(*args, **kwargs)
File "WebApp35\lib\site-packages\flask\views.py", line 84, in view
return self.dispatch_request(*args, **kwargs)
File "WebApp35\lib\site-packages\flask_restful\__init__.py", line 587, in dispatch_request
resp = meth(*args, **kwargs)
File "app\handlers\nodeHandlers.py", line 70, in get
return DataManager.get_suggestion(suggestion_string), 201, {
File "app\adapter\dataManager.py", line 44, in get_suggestion
return cls.adapter.get_suggestion(suggestion_string)
File "app\adapter\neoAdapter.py", line 337, in get_suggestion
for node in cls.cypher.run(query):
File "WebApp35\lib\site-packages\py2neo\database\__init__.py", line 676, in run
return self.begin(autocommit=True).run(statement, parameters, **kwparameters)
File "WebApp35\lib\site-packages\py2neo\database\__init__.py", line 351, in begin
return self.transaction_class(self, autocommit)
File "WebApp35\lib\site-packages\py2neo\database\__init__.py", line 1171, in __init__
self.session = driver.session()
File "WebApp35\lib\site-packages\py2neo\packages\neo4j\v1\session.py", line 148, in session
session = Session(self)
File "WebApp35\lib\site-packages\py2neo\packages\neo4j\v1\session.py", line 461, in __init__
self.connection = connect(driver.host, driver.port, driver.ssl_context, **driver.config)
File "WebApp35\lib\site-packages\py2neo\packages\neo4j\v1\connection.py", line 399, in connect
raise error
py2neo.packages.neo4j.v1.exceptions.ProtocolError: Cannot establish secure connection; [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:720)

Getting error Client sent AUTH, but no password is set while initializing Redis object

I am fairly new to redis and using configuring redis with flask app.
i have edited redis.conf file and uncommented requirepass
requirepass foobared
and I am able to get into redid-cli using this password.
like this ./redis-cli -h 127.0.0.1 -p 6379 -a foobared
but when I try to initialise an object of Redis class by passing in the password,
>>> import os
>>> import redis
>>> from flask import Flask
>>> from redis import Redis
>>> app = Flask('weatherApp')
>>> app.config["REDIS_HOST"] = os.getenv("REDIS_HOST")
>>> app.config["REDIS_PORT"] = os.getenv("REDIS_PORT")
>>> app.config["REDIS_PWD"] = os.getenv("REDIS_PWD")
>>> app
<Flask 'weatherApp'>
>>> app.config
>>> redis = Redis(app.config["REDIS_HOST"], port=app.config["REDIS_PORT"],
... db=0, password=app.config["REDIS_PWD"])
>>> redis.client_list()
I keep getting the error saying:
Traceback (most recent call last):
File "/Users/ciasto-piekarz/Development/web/python/flask/flsk-dimnd/venv/lib/python2.7/site-packages/flask/app.py", line 2000, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/ciasto-piekarz/Development/web/python/flask/flsk-dimnd/venv/lib/python2.7/site-packages/flask/app.py", line 1991, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Users/ciasto-piekarz/Development/web/python/flask/flsk-dimnd/venv/lib/python2.7/site-packages/flask/app.py", line 1567, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/ciasto-piekarz/Development/web/python/flask/flsk-dimnd/venv/lib/python2.7/site-packages/flask/app.py", line 1988, in wsgi_app
response = self.full_dispatch_request()
File "/Users/ciasto-piekarz/Development/web/python/flask/flsk-dimnd/venv/lib/python2.7/site-packages/flask/app.py", line 1641, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/ciasto-piekarz/Development/web/python/flask/flsk-dimnd/venv/lib/python2.7/site-packages/flask/app.py", line 1544, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/ciasto-piekarz/Development/web/python/flask/flsk-dimnd/venv/lib/python2.7/site-packages/flask/app.py", line 1639, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/ciasto-piekarz/Development/web/python/flask/flsk-dimnd/venv/lib/python2.7/site-packages/flask/app.py", line 1625, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/ciasto-piekarz/Development/web/python/flask/flsk-dimnd/venv/lib/python2.7/site-packages/flask/views.py", line 84, in view
return self.dispatch_request(*args, **kwargs)
File "/Users/ciasto-piekarz/Development/web/python/weatherApp/src/views.py", line 192, in dispatch_request
print redis.client_list()
File "/Users/ciasto-piekarz/Development/web/python/flask/flsk-dimnd/venv/lib/python2.7/site-packages/redis/client.py", line 703, in client_list
return self.execute_command('CLIENT LIST')
File "/Users/ciasto-piekarz/Development/web/python/flask/flsk-dimnd/venv/lib/python2.7/site-packages/redis/client.py", line 667, in execute_command
connection.send_command(*args)
File "/Users/ciasto-piekarz/Development/web/python/flask/flsk-dimnd/venv/lib/python2.7/site-packages/redis/connection.py", line 610, in send_command
self.send_packed_command(self.pack_command(*args))
File "/Users/ciasto-piekarz/Development/web/python/flask/flsk-dimnd/venv/lib/python2.7/site-packages/redis/connection.py", line 585, in send_packed_command
self.connect()
File "/Users/ciasto-piekarz/Development/web/python/flask/flsk-dimnd/venv/lib/python2.7/site-packages/redis/connection.py", line 493, in connect
self.on_connect()
File "/Users/ciasto-piekarz/Development/web/python/flask/flsk-dimnd/venv/lib/python2.7/site-packages/redis/connection.py", line 561, in on_connect
if nativestr(self.read_response()) != 'OK':
File "/Users/ciasto-piekarz/Development/web/python/flask/flsk-dimnd/venv/lib/python2.7/site-packages/redis/connection.py", line 629, in read_response
raise response
ResponseError: Client sent AUTH, but no password is set
Any help will be greatly appreciated!

How to make a post request in flask post method?

I am trying to wrote some code using flask let another server can post some data to it and then inside flask, when I receive the call from outside, I would like to make another post to another server.
Below is my code
from flask import Flask, jsonify, request
import json
import requests
app = Flask(__name__)
#app.route("/sendData.json", methods=['POST'])
def receiveImageData():
imageData = request.json
# save data to son file
with open(request.json['image_filename'].split('.')[0] + '.json', 'w+') as f:
json.dump(imageData, f, indent=4)
# post some data to this url
r = requests.post('http://example.com/example.json', son = {'image_filename':'test.jpg', 'image_url': "http://images.come"})
# return json data back for /sendData.json
return jsonify({"status": "success"})
The problem is the last line {'status':'success'} will not return for sendData.json.
How can I fix it or there should be another way to make this happen?
Below is error log from flask
127.0.0.1 - - [03/Aug/2017 14:38:37] "POST /sendData.json HTTP/1.1" 500 -
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/bloomer/Documents/python/api_server/api.py", line 21, in receiveImageData
r = requests.post('http://example.com/example.json', son = {'image_filename':'test.jpg', 'image_url': "http://images.come"})
File "/usr/local/lib/python2.7/site-packages/requests/api.py", line 112, in post
return request('post', url, data=data, json=json, **kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/adapters.py", line 490, in send
raise ConnectionError(err, request=request)
ConnectionError: ('Connection aborted.', BadStatusLine("''",))
instead of jsonify({"status": "success"}) Use :
return (Response(),200)
Try it out with return Response(), 200 at the end of receiveImageData().
EDIT:
I researched a bit. Actually it should work. Try something like:
return jsonify({"success": True}), 202
What are the error messages you get? And is it the same server / API, where you post your data and status: success?

Flask + gevent + uwsgi - greenlet spawn cause 502 Bad Gateway

I have an issue since I added gevent to my flask project: the page spawning greenlets always timeout / bad gateway.
The part of code causing this issue is this: https://github.com/Kyria/LazyBlacksmith/blob/master/lazyblacksmith/views/ajax.py#L145-L221
Here what i've tested:
Running my flask app with python app.py : works fine with or without gevent/greenlets.
Running behind uwsgi without gevent/greenlet : works fine.
Running behind uwsgi with gevent/greenlet : fails.
So, after searching for a while, reading uwsgi doc, i tried to add some stuff to my uwsgi conf :
loop = async
async = 10
greenlet = true
ugreen = true
After restarting my uwsgi, i didn't have to wait for error, the Bad Gateway was really quick, but with an error in the log this time:
Traceback (most recent call last):
File "/home/lazyblacksmith/LazyBlacksmith/env/local/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/home/lazyblacksmith/LazyBlacksmith/env/local/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/home/lazyblacksmith/LazyBlacksmith/env/local/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/lazyblacksmith/LazyBlacksmith/env/local/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/home/lazyblacksmith/LazyBlacksmith/env/local/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/lazyblacksmith/LazyBlacksmith/env/local/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/lazyblacksmith/LazyBlacksmith/env/local/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/home/lazyblacksmith/LazyBlacksmith/env/local/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "./lazyblacksmith/views/ajax.py", line 152, in get_price_and_tax
crest = get_crest()
File "./lazyblacksmith/utils/crestutils.py", line 17, in get_crest
crest()
File "./lazyblacksmith/utils/pycrest/eve.py", line 212, in __call__
self._data = APIObject(self.get(self._endpoint), self)
File "./lazyblacksmith/utils/pycrest/eve.py", line 156, in get
res = self._session.get(resource, params=prms, headers=headers)
File "/home/lazyblacksmith/LazyBlacksmith/env/local/lib/python2.7/site-packages/requests/sessions.py", line 480, in get
return self.request('GET', url, **kwargs)
File "/home/lazyblacksmith/LazyBlacksmith/env/local/lib/python2.7/site-packages/requests/sessions.py", line 468, in request
resp = self.send(prep, **send_kwargs)
File "/home/lazyblacksmith/LazyBlacksmith/env/local/lib/python2.7/site-packages/requests/sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "/home/lazyblacksmith/LazyBlacksmith/env/local/lib/python2.7/site-packages/requests/adapters.py", line 370, in send
timeout=timeout
File "/home/lazyblacksmith/LazyBlacksmith/env/local/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 559, in urlopen
body=body, headers=headers)
File "/home/lazyblacksmith/LazyBlacksmith/env/local/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 345, in _make_request
self._validate_conn(conn)
File "/home/lazyblacksmith/LazyBlacksmith/env/local/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 782, in _validate_conn
conn.connect()
File "/home/lazyblacksmith/LazyBlacksmith/env/local/lib/python2.7/site-packages/requests/packages/urllib3/connection.py", line 215, in connect
conn = self._new_conn()
File "/home/lazyblacksmith/LazyBlacksmith/env/local/lib/python2.7/site-packages/requests/packages/urllib3/connection.py", line 135, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File "/home/lazyblacksmith/LazyBlacksmith/env/local/lib/python2.7/site-packages/requests/packages/urllib3/util/connection.py", line 66, in create_connection
for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
File "/home/lazyblacksmith/LazyBlacksmith/env/local/lib/python2.7/site-packages/gevent/_socketcommon.py", line 268, in getaddrinfo
return get_hub().resolver.getaddrinfo(host, port, family, socktype, proto, flags)
File "/home/lazyblacksmith/LazyBlacksmith/env/local/lib/python2.7/site-packages/gevent/resolver_thread.py", line 64, in getaddrinfo
return self.pool.apply(_socket.getaddrinfo, args, kwargs)
File "/home/lazyblacksmith/LazyBlacksmith/env/local/lib/python2.7/site-packages/gevent/pool.py", line 300, in apply
return self.spawn(func, *args, **kwds).get()
File "/home/lazyblacksmith/LazyBlacksmith/env/local/lib/python2.7/site-packages/gevent/event.py", line 284, in get
result = self.hub.switch()
File "/home/lazyblacksmith/LazyBlacksmith/env/local/lib/python2.7/site-packages/gevent/hub.py", line 592, in switch
return greenlet.switch(self)
MemoryError
I also tried to add the following in my uwsgi app conf :
gevent = 10
gevent-monkey-patch = true
limit-as = 512
And i tried to increase the timeout in nginx uwsgi_read_timeout 300, but it didn't change anything...
My uwsgi conf is the following:
# lazyblacksmith.ini file
[uwsgi]
chdir = /home/lazyblacksmith/LazyBlacksmith
home = /home/lazyblacksmith/LazyBlacksmith/env/
callable = app
wsgi-file = app.py
master = true
processes = 10
socket = /home/lazyblacksmith/LazyBlacksmith/env/lazyblacksmith.socket
chmod-socket = 664
vacuum = true
uid = lazyblacksmith
gid = www-data
My nginx conf :
upstream lbflask {
server unix:/home/lazyblacksmith/LazyBlacksmith/env/lazyblacksmith.socket;
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name site.com; #
charset utf-8;
location /static {
alias /home/lazyblacksmith/LazyBlacksmith/lazyblacksmith/static;
include /etc/nginx/mime.types;
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass lbflask;
include /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
}
}
I don't find anything relevant anymore :/ I think i'll end up moving my gevent stuff in tasks (with celery), but i still want to understand what is my problem...
For information:
Debian 8
uwsgi 2.0.7-debian
nginx/1.6.2
python 2.7.9
gevent 1.1rc2
greenlet 0.4.9
Thank you !

Categories

Resources