简体   繁体   English

从python + flask + gunicorn + nginx + Compute Engine应用程序中读取来自Google Cloud Storage的文件失败

[英]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.

相关问题 在Google App Engine(python)中从Google Cloud Storage读取文件时发生内存泄漏 - Memory leak in reading files from Google Cloud Storage at Google App Engine (python) 如何从Google App Engine读取Google Cloud Storage文件 - How to read a Google Cloud Storage file from Google App Engine 获取文件的公共 URL - Google Cloud Storage - App Engine (Python) - Get Public URL for File - Google Cloud Storage - App Engine (Python) 允许谷歌云计算引擎实例将文件写入谷歌存储桶 - Python - Allow Google Cloud Compute Engine Instance to write file to Google Storage Bucket - Python 无法在Google App Engine和Python上显示来自云存储的图像 - Trouble displaying image from cloud storage on Google App Engine, Python 无法从App Engine中的Google云端存储中读取文件内容 - Not able to read file content from google cloud storage in app engine 如何允许用户在不公开访问的情况下从Compute Engine下载Google Cloud Storage文件 - How to allow a user to download a Google Cloud Storage file from Compute Engine without public access 使用XLRD从Google Cloud Storage读取文件(python) - Reading a file from Google Cloud Storage with XLRD (python) Google Cloud Compute Engine上的Flask + NGINX + UWSGI提供了502错误的网关 - Flask+NGINX+UWSGI on Google Cloud Compute Engine gives 502 bad gateway 使用Google App Engine将文件上传到Google云端存储(Python) - Upload Files To Google Cloud Storage With Google App Engine (Python)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM