admin管理员组文章数量:1303670
Following situation: I want to load and read bufr files from a specific url without downloading it on my disk. That´s what i've done so far:
import requests
from io import BytesIO
import eccodes as ecc
my_url = ".bufr"
with requests.request(method='GET', url=my_url, headers={'cache-control': "no-cache"}) as response:
if response.ok:
with open(BytesIO(response.content), 'rb') as fp:
num_msgs = ecc.codes_count_in_file(fp)
bid = ecc.codes_bufr_new_from_file(fp)
print(num_msgs)
else:
print(f'{response.reason}')
This results into:
TypeError: expected str, bytes or os.PathLike object, not BytesIO
Has anyone an idea to change this code into a successful piece of text? :)
best regards.
Ich changed the code to:
import requests
from io import BytesIO
import eccodes as ecc
my_url = ".bufr"
with requests.request(method='GET', url=my_url, headers={'cache-control': "no-cache"}) as response:
if response.ok:
with BytesIO(response.content) as fp:
num_msgs = ecc.codes_count_in_file(fp)
bid = ecc.codes_bufr_new_from_file(fp)
print(num_msgs)
else:
And it works. But it raises a neu error.
fileno Traceback (most recent call last): File "lib/python3.10/site-packages/gribapi/gribapi.py", line 435, in grib_count_in_file err = lib.grib_count_in_file(ffi.NULL, fileobj, num_p) io.UnsupportedOperation: fileno
本文标签: python 3xHow to open ioBytesIO() Object to read bufr files from urlStack Overflow
版权声明:本文标题:python 3.x - How to open io.BytesIO() Object to read bufr files from url? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741769868a2396687.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论