简体   繁体   English

Python:ValueError仅在AppEngine上发生,但在本地工作正常

[英]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. 唯一的例外说,您的输入数据包含逗号,所以你的期望totaltime23: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. 另请注意,日期字符串( timedatetime time datetimedatetime区域设置),这可能解释了开发系统与AppEngine之间的差异。

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

相关问题 找不到Python模块 <project> 仅在VPS上。 在本地计算机上工作正常 - Python module not found <project> only on VPS. works fine on local machine 当localhost正常工作和MacOSX时,可以通过本地IP地址访问AppEngine SDK站点 - Can access AppEngine SDK sites via local ip-address when localhost works just fine and a MacOSX 本地上的Appengine Python数据存储区 - Appengine python datastore on local ValueError:信号仅在主线程中有效(Python / Scrapy + Flask) - ValueError: signal only works in main thread (Python / Scrapy + Flask ) Python 信号:ValueError:信号仅在主线程中有效 - Python signals: ValueError: signal only works in main thread Cron在本地主机上工作,但在部署Appengine时不工作 - Cron works on local host but not when deployed Appengine 为什么Python Socket只在本地网络上工作? - Why Python Socket works only on local network? 阅读文档本地安装:Celery ValueError: signal only works in main thread - Read the Docs local install: Celery ValueError: signal only works in main thread Google AppEngine:仅在本地开发中使用python库。 识别环境 - Google AppEngine: Use python library only in Local Development. Identifying environment Azure ML Studio 环境中的 Python 自定义模型错误 0085,在本地环境中工作正常 - Python Custom Model in Azure ML Studio Environment Error 0085, Works fine in Local Environment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM