Reading of a file from Google Cloud Storage fails in a python + flask + gunicorn + nginx + Compute Engine app

萝らか妹 提交于 2019-12-10 14:56:21

问题


Reading of a file downloaded from Google Cloud Storage fails in a python + flask + gunicorn + nginx + Compute Engine app. Link to the code: 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:

prj_blob.download_to_file(self.prj_file)
logger.log_text(self.prj_file)
line 64 -->       euref_fin.ImportFromWkt(self.prj_file.read())).

回答1:


file.seek(0) helped to solve the problem; somehow I assume that after blob.download_to_file(file_name) the file reader isn't in the start of the file. 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)


来源:https://stackoverflow.com/questions/53631410/reading-of-a-file-from-google-cloud-storage-fails-in-a-python-flask-gunicorn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!