简体   繁体   English

Heroku因“文件中非ASCII字符'\\ xe2'”错误而崩溃

[英]Heroku crashing due to “Non-ASCII character '\xe2' in file” error

I'm trying to set up an Flask app on Heroku, but Heroku seems to keep on crashing. 我正在尝试在Heroku上设置Flask应用,但Heroku似乎一直崩溃。 In the Heroku logs, it appears that Heroku is crashing due to this error: 在Heroku日志中,似乎Heroku因此错误而崩溃:

SyntaxError: Non-ASCII character '\xe2' in file /app/app/range_parser.py on line 8, but no encoding declared;

Here are the following steps that I've taken to (attempt to) solve the problem: 以下是我尝试(尝试)解决问题的以下步骤:

  • Set default Heroku encoding to UTF-8 via heroku config:add LANG=en_US.UTF-8 通过heroku config:add LANG=en_US.UTF-8将默认的Heroku编码设置为UTF-8 heroku config:add LANG=en_US.UTF-8
  • Added # -*- coding: utf-8 -*- , # encoding=utf8 , and # coding: utf-8 to the header of the file 在文件头中添加了# -*- coding: utf-8 -*-# encoding=utf8# coding: utf-8
  • Setting up runtime.txt file in root with runtime set to python-3.4.3 在运行时设置为python-3.4.3根目录中设置runtime.txt文件
    • Note: after redeploying the app, the build still reads -----> Installing runtime (python-2.7.11) , so I'm not actually sure if heroku is actually registering the runtime.txt file. 注意:重新部署应用程序后,构建仍显示为-----> Installing runtime (python-2.7.11) ,因此我实际上不确定heroku是否正在实际注册runtime.txt文件。 Is there a way to check? 有没有办法检查?
  • Messing around with the actual file in question. 与实际的文件纠缠不清。 It appears that when I erase everything in the file but the header and have it return none , it's still giving me the same error on line 8 (even when there aren't even 8 lines in the file). 看来,当我擦除文件中除头文件之外的所有内容并使它不返回none ,它仍在第8行上给我同样的错误(即使文件中甚至没有8行)。 This leads me to believe that the error probably stems from a runtime version/other error not directly related to the file itself. 这使我相信该错误可能源于运行时版本/其他与文件本身不直接相关的错误。
  • Lastly, deploying the app locally, through the run.py file, and through heroku local . 最后,通过run.py文件和heroku local在本地部署应用程序。 This, surprisingly, works, again leading me to believe that the problem is with Heroku and not the file. 令人惊讶的是,这有效,再次使我相信问题出在Heroku而不是文件。

How do I resolve this problem? 我该如何解决这个问题?

My guess it the at line 8 of your app range_parser.py you have code that takes unicode instead of encoded utf-8 string and crashes the app. 我猜在应用程序range_parser.py的第8行,您的代码采用了unicode而不是编码的utf-8字符串,并使应用程序崩溃。 Check if you have some kind of text assignment, transformation or some kind of use and encode it to utf-8. 检查您是否具有某种文本分配,转换或某种使用方式,并将其编码为utf-8。 Something like: 就像是:

your_var.encode('utf-8') #if it is a unicode string

Figured out why Heroku was crashing. 弄清楚Heroku为何崩溃。

My mistake was that even though I set up runtime.txt to build python-3.4.3, I forgot to commit and push the file, and git push heroku master to rebuild the runtime. 我的错误是,即使我设置了runtime.txt来构建python-3.4.3,我也忘记了提交和推送文件,而git push heroku master重建了运行时。

Not sure why the encoding error occurred in the first place, but with 3.4.3 it seems to be fixed. 不知道为什么首先会发生编码错误,但是对于3.4.3,它似乎已修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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