[英]Reading of a file from Google Cloud Storage fails in a python + flask + gunicorn + nginx + Compute Engine app
Reading of a file downloaded from Google Cloud Storage fails in a python + flask + gunicorn + nginx + Compute Engine app. 从python + flask + gunicorn + nginx + Compute Engine应用程序中读取从Google Cloud Storage下载的文件失败。 Link to the code: https://github.com/samuq/CE-test . 链接到代码: https : //github.com/samuq/CE-test 。 The line number 64 of the file 'ETL_SHP_READ_SQL_WRITE' returns nothing, although the file is valid and has data in it: 文件'ETL_SHP_READ_SQL_WRITE'的第64行没有返回任何内容,尽管该文件有效并且其中包含数据:
prj_blob.download_to_file(self.prj_file)
logger.log_text(self.prj_file)
line 64 --> euref_fin.ImportFromWkt(self.prj_file.read())).
file.seek(0) helped to solve the problem; file.seek(0)帮助解决了这个问题; somehow I assume that after blob.download_to_file(file_name) the file reader isn't in the start of the file. 不知怎的,我假设在blob.download_to_file(file_name)之后文件阅读器不在文件的开头。 Code: 码:
try:
fd, path = tempfile.mkstemp()
with os.fdopen(fd, 'w+') as prj_file:
# do stuff with temp file
prj_blob.download_to_file(prj_file)
prj_file.seek(0)
euref_fin.ImportFromWkt(prj_file.read())
logger.log_text(str(euref_fin))
logger.log_text('euref_fin printed!')
finally:
os.remove(path)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.