Heroku内部服务器错误-ValueError:无效的标头值b

时间:2019-01-09 21:10:17

标签: python heroku

我对使用Heroku并不陌生,并且完全陷入了这个错误。我的flask应用程序可以在本地计算机上完美运行,并且可以在本地使用AerisWeather Python SDK进行API调用。但是,将它部署到Heroku之后,我看不到这个“内部服务器错误”。以下是错误日志的一部分,我认为这表明标头存在问题,但由于我没有任何明确定义标头的代码,因此我不知道如何解决该问题。 Heroku是否设置了我可以查看的标题?任何帮助将不胜感激,并在此先感谢。

2019-01-09T21:25:02.611924+00:00 heroku[router]: at=info method=GET path="/" host=mlcc-dashboard.herokuapp.com request_id=06d623f5-cf8e-4d5f-a7d5-8af44cd27805 fwd="64.134.157.188" dyno=web.1 connect=0ms service=7ms status=500 bytes=456 protocol=https
2019-01-09T21:25:02.610887+00:00 app[web.1]: [2019-01-09 21:25:02,609] ERROR in app: Exception on / [GET]
2019-01-09T21:25:02.610917+00:00 app[web.1]: Traceback (most recent call last):
2019-01-09T21:25:02.610921+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
2019-01-09T21:25:02.610923+00:00 app[web.1]:     response = self.full_dispatch_request()
2019-01-09T21:25:02.610925+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request
2019-01-09T21:25:02.610927+00:00 app[web.1]:     rv = self.handle_user_exception(e)
2019-01-09T21:25:02.610928+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception
2019-01-09T21:25:02.610930+00:00 app[web.1]:     reraise(exc_type, exc_value, tb)
2019-01-09T21:25:02.610932+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
2019-01-09T21:25:02.610935+00:00 app[web.1]:     raise value
2019-01-09T21:25:02.610937+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
2019-01-09T21:25:02.610938+00:00 app[web.1]:     rv = self.dispatch_request()
2019-01-09T21:25:02.610940+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request
2019-01-09T21:25:02.610941+00:00 app[web.1]:     return self.view_functions[rule.endpoint](**req.view_args)
2019-01-09T21:25:02.610943+00:00 app[web.1]:   File "/app/mlcc_dashboard/app.py", line 105, in index
2019-01-09T21:25:02.610945+00:00 app[web.1]:     response_list = aeris.batch_request(endpoints=endpoints, global_location=loc)
2019-01-09T21:25:02.610947+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/aerisweather/aerisweather.py", line 178, in batch_request
2019-01-09T21:25:02.610949+00:00 app[web.1]:     json_obj = network.get_json(url, self.app_id)
2019-01-09T21:25:02.610950+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/aerisweather/utils/AerisNetwork.py", line 27, in get_json
2019-01-09T21:25:02.610953+00:00 app[web.1]:     resp = request.urlopen(req)
2019-01-09T21:25:02.610954+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/urllib/request.py", line 223, in urlopen
2019-01-09T21:25:02.610956+00:00 app[web.1]:     return opener.open(url, data, timeout)
2019-01-09T21:25:02.610959+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/urllib/request.py", line 526, in open
2019-01-09T21:25:02.610960+00:00 app[web.1]:     response = self._open(req, data)
2019-01-09T21:25:02.610962+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/urllib/request.py", line 544, in _open
2019-01-09T21:25:02.610963+00:00 app[web.1]:     '_open', req)
2019-01-09T21:25:02.610965+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/urllib/request.py", line 504, in _call_chain
2019-01-09T21:25:02.610966+00:00 app[web.1]:     result = func(*args)
2019-01-09T21:25:02.610968+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/urllib/request.py", line 1361, in https_open
2019-01-09T21:25:02.610970+00:00 app[web.1]:     context=self._context, check_hostname=self._check_hostname)
2019-01-09T21:25:02.610971+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/urllib/request.py", line 1318, in do_open
2019-01-09T21:25:02.610973+00:00 app[web.1]:     encode_chunked=req.has_header('Transfer-encoding'))
2019-01-09T21:25:02.610974+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/http/client.py", line 1239, in request
2019-01-09T21:25:02.610976+00:00 app[web.1]:     self._send_request(method, url, body, headers, encode_chunked)
2019-01-09T21:25:02.610977+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/http/client.py", line 1280, in _send_request
2019-01-09T21:25:02.610979+00:00 app[web.1]:     self.putheader(hdr, value)
2019-01-09T21:25:02.610980+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/http/client.py", line 1217, in putheader
2019-01-09T21:25:02.610982+00:00 app[web.1]:     raise ValueError('Invalid header value %r' % (values[i],))
2019-01-09T21:25:02.610990+00:00 app[web.1]: ValueError: Invalid header value b'AerisPythonSDK/0.3.0/Python/3.6.2 (default, May 22 2018, 20:38:47) \n[GCC 7.3.0]'
2019-01-09T21:25:02.612416+00:00 app[web.1]: 10.95.237.176 - - [09/Jan/2019:21:25:02 +0000] "GET / HTTP/1.1" 500 291 "https://dashboard.heroku.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"

烧瓶路径的代码:

@app.route("/")
def index():
    """Render Home Page"""
    aeris = AerisWeather(client_id, client_secret, app_id)
    loc = RequestLocation(city="boston", state="ma")
    obs_dict = {}   
    global aerisTemp
    endpoint1 = Endpoint(endpoint_type=EndpointType.OBSERVATIONS, action=RequestAction.OBSERVATIONS.CLOSEST, params={ParameterType.OBSERVATIONS.P: "02101"})
    endpoint2 = Endpoint(endpoint_type=EndpointType.OBSERVATIONS_SUMMARY)
    endpoints = [endpoint1, endpoint2]  
    response_list = aeris.batch_request(endpoints=endpoints, global_location=loc)   
    for resp in response_list:  
        if type(resp) is ObservationsResponse:
            obs = resp
            ob = obs.ob
            obs_dict.update(timestamp = str(ob.timestamp))
            obs_dict.update(humidity = str(ob.humidity))
            obs_dict.update(isDay = str(ob.isDay))
            obs_dict.update(tempF = str(ob.tempF))
            obs_dict.update(weatherPrimaryCoded = str(ob.weatherPrimaryCoded))
            obs_dict.update(weatherShort = str(ob.weatherShort))
        elif type(resp) is ObservationsSummaryResponse:
            ob_sum = resp
            periods = ob_sum.periods
            temp = periods[0].temp
            aerisTemp = temp.avgF
            obs_dict.update(avgTempF = str(temp.avgF))
            obs_dict.update(precipMM = str(periods[0].precip.totalMM))

    return render_template("index.html", data=obs_dict)

0 个答案:

没有答案