[英]Python: ValueError only happening on AppEngine but works fine local
This is strange. 这很奇怪。 Run the code and it works fine on local server but when uploading it to app engine it doesn't work at all and gets the error:
运行代码,它可以在本地服务器上正常工作,但是将其上传到应用程序引擎时根本不起作用,并显示错误消息:
if int(totaltime[0:2]) == 23 and int(totaltime[3:5]) >= 45:
ValueError: invalid literal for int() with base 10: ', '
Here is the code that is triggering it: 这是触发它的代码:
if int(totaltime[0:2]) == 23 and int(totaltime[3:5]) >= 45:
ta = "yes"
else:
ta = "no"
totaltime is 23:27:35 so int(totaltime[0:2]) gets 23 and (totaltime[3:5]) gets 27. I don't understand why this doesn't work online but works fine local. totaltime是23:27:35,所以int(totaltime [0:2])得到23,而(totaltime [3:5])得到27。我不明白为什么这不能在线工作但是在本地可以正常工作。
The exception says that your input data contains a comma, so your expectation of totaltime
being 23:27:35
is clearly violated. 唯一的例外说,您的输入数据包含逗号,所以你的期望
totaltime
是23:27:35
的明显违反。
Try outputting repr(totaltime[0:2])
and repr(totaltime[3:5])
on Appengine. 尝试在
repr(totaltime[0:2])
输出repr(totaltime[0:2])
和repr(totaltime[3:5])
。
Also, you can split the if-statement into two lines like so: 同样,您可以将if语句分成两行,如下所示:
if (int(totaltime[0:2]) == 23 and
int(totaltime[3:5]) >= 45):
That will let you see which of the calls to int()
triggers the ValueError
, making debugging a bit easier. 这样一来,您便可以查看对
int()
哪些调用会触发ValueError
,从而使调试更加容易。
Also be aware that date strings (both from time
and datetime
honor the locale settings, which may explain the discrepancy between your development system and AppEngine. 另请注意,日期字符串(
time
和datetime
time
datetime
均datetime
区域设置),这可能解释了开发系统与AppEngine之间的差异。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.