我正在尝试运行一个项目,但每当我尝试加载一个特定页面时,它都会丢弃以下错误:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask_restplus/api.py", line 536, in error_router
return original_handler(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/nitin/Desktop/open-event-orga-server/app/views/users/events.py", line 91, in create_view
current_timezone = get_current_timezone()
File "/home/nitin/Desktop/open-event-orga-server/app/helpers/wizard/helpers.py", line 17, in get_current_timezone
match = geolite2.lookup(get_real_ip(True) or '127.0.0.1')
File "/usr/local/lib/python2.7/dist-packages/geoip.py", line 364, in lookup
return self._get_actual_db().lookup(ip_addr)
File "/usr/local/lib/python2.7/dist-packages/geoip.py", line 204, in lookup
return self._lookup(ip_addr)
File "/usr/local/lib/python2.7/dist-packages/geoip.py", line 249, in _lookup
packed_addr = pack_ip(ip_addr)
File "/usr/local/lib/python2.7/dist-packages/geoip.py", line 37, in pack_ip
raise ValueError('Malformed IP address')
ValueError: Malformed IP address
[2017-01-22 00:34:24 +0000] [6835] [ERROR] Error handling request /socket.io/?EIO=3&transport=websocket&sid=8bed14818d4046edb35bbc87f27d5164
而且我无法弄清楚错误的IP地址究竟是什么以及此错误背后的原因。
以下是get_current_timezone()函数:
def get_current_timezone():
match = geolite2.lookup(get_real_ip(True) or '127.0.0.1')
if match is not None:
return match.timezone
else:
return 'UTC'
以下是get_real_ip()方法:
def get_real_ip(local_correct=False):
try:
if 'X-Forwarded-For' in request.headers:
ip = request.headers.getlist("X-Forwarded-For")[0].rpartition(' ')[-1]
else:
ip = request.remote_addr or None
if local_correct and (ip == '127.0.0.1' or ip == '0.0.0.0'):
ip = urlopen('http://ip.42.pl/raw').read() # On local test environments
except:
ip = None
return ip
以下是创建此问题的创建事件视图的一部分。:
@events.route('/create/', defaults={'step': ''})
@events.route('/create/<step>')
def create_view(step):
if step != '':
return redirect(url_for('.create_view', step=''))
hash = get_random_hash()
if CallForPaper.query.filter_by(hash=hash).all():
hash = get_random_hash()
current_timezone = get_current_timezone()
return render_template(
'gentelella/admin/event/wizard/wizard.html',
current_date=datetime.datetime.now(),
event_types=DataGetter.get_event_types(),
event_licences=DataGetter.get_event_licences(),
event_topics=DataGetter.get_event_topics(),
event_sub_topics=DataGetter.get_event_subtopics(),
timezones=DataGetter.get_all_timezones(),
cfs_hash=hash,
current_timezone=current_timezone,
payment_countries=DataGetter.get_payment_countries(),
payment_currencies=DataGetter.get_payment_currencies(),
included_settings=get_module_settings())