79099365

Date: 2024-10-17 18:19:44
Score: 0.5
Natty:
Report link

You are getting that error because the object that you retrieved using the requests library in Python does not have an attribute or method like tell().

Based on this documentation, you can either use response.text to read the content response from the server. You can also use response.json() if you are dealing with data in JSON format. If you want to get a raw stream of bytes of your data, use response.raw and set stream=True at first when making the request.

Since you are working with stream upload using upload_from_file, you can try using response.raw in your code. Here’s an example:

import requests
from google.cloud import storage


url = "https://people.sc.fsu.edu/~jburkardt/data/csv/addresses.csv"

# GCP info
client = storage.Client(project="my-project")
bucket = client.get_bucket('my-bucket')
target_blob = bucket.blob("test/report_01.csv")

with requests.get(url, stream=True) as f:
    target_blob.upload_from_file(f.raw)

Reasons:
  • Blacklisted phrase (1): this document
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: yannco