Skip to content

Commit d06561c

Browse files
authored
fix: migrate storage samples to use download_as_bytes() (GoogleCloudPlatform#9862)
1 parent 30f5069 commit d06561c

7 files changed

Lines changed: 8 additions & 8 deletions

File tree

data-science-onramp/data-ingestion/ingestion_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def get_dataproc_job_output(result):
145145
"""Get the dataproc job logs in plain text"""
146146
output_location = result.driver_output_resource_uri + ".000000000"
147147
blob = get_blob_from_path(output_location)
148-
return blob.download_as_string().decode("utf-8")
148+
return blob.download_as_bytes().decode("utf-8")
149149

150150

151151
def assert_table_success_message(table_name, out):

data-science-onramp/data-processing/process_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def test_process():
179179
# Get job output
180180
output_location = result.driver_output_resource_uri + ".000000000"
181181
blob = get_blob_from_path(output_location)
182-
out = blob.download_as_string().decode("utf-8")
182+
out = blob.download_as_bytes().decode("utf-8")
183183

184184
# trip duration
185185
assert not is_in_table(r"\d*.\d* s", out)

dataproc/snippets/quickstart/quickstart.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def quickstart(project_id, region, cluster_name, job_file_path):
8181
storage.Client()
8282
.get_bucket(matches.group(1))
8383
.blob(f"{matches.group(2)}.000000000")
84-
.download_as_string()
84+
.download_as_bytes().decode("utf-8")
8585
)
8686

8787
print(f"Job finished successfully: {output}")

dataproc/snippets/submit_job.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def submit_job(project_id, region, cluster_name):
6363
storage.Client()
6464
.get_bucket(matches.group(1))
6565
.blob(f"{matches.group(2)}.000000000")
66-
.download_as_string()
66+
.download_as_bytes().decode("utf-8")
6767
)
6868

6969
print(f"Job finished successfully: {output}")

dataproc/snippets/submit_job_to_cluster.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def download_output(project, cluster_id, output_bucket, job_id):
7474
output_blob = "google-cloud-dataproc-metainfo/{}/jobs/{}/driveroutput.000000000".format(
7575
cluster_id, job_id
7676
)
77-
return bucket.blob(output_blob).download_as_string()
77+
return bucket.blob(output_blob).download_as_bytes().decode("utf-8")
7878

7979

8080
# [START dataproc_create_cluster]
@@ -132,7 +132,7 @@ def quickstart(project_id, region, cluster_name, gcs_bucket, pyspark_file):
132132
storage.Client()
133133
.get_bucket(matches.group(1))
134134
.blob(f"{matches.group(2)}.000000000")
135-
.download_as_string()
135+
.download_as_bytes().decode("utf-8")
136136
)
137137

138138
print(f"Job finished successfully: {output}\r\n")

vision/snippets/detect/beta_snippets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def async_batch_annotate_images_uri(input_image_uri, output_uri):
346346
# annotations for the first two annotate image requests.
347347
output = blob_list[0]
348348

349-
json_string = output.download_as_string()
349+
json_string = output.download_as_bytes().decode("utf-8")
350350
response = vision.BatchAnnotateImagesResponse.from_json(json_string)
351351

352352
# Prints the actual response for the first annotate image request.

vision/snippets/detect/detect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ def async_detect_document(gcs_source_uri, gcs_destination_uri):
861861
# the first two pages of the input file.
862862
output = blob_list[0]
863863

864-
json_string = output.download_as_string()
864+
json_string = output.download_as_bytes().decode("utf-8")
865865
response = json.loads(json_string)
866866

867867
# The actual response for the first page of the input file.

0 commit comments

Comments
 (0)