You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, Im getting this error since mid Mar when before it was working well.
Environment details
OS type and version: deploy in the google cloud functions
Python version: 3.11
pip version: -
google-cloud-storage 2.16.0
Code example
# example
`importloggingimportosimportrandomimportrequestsimportstringfrombs4importBeautifulSoupfromgoogle.cloudimportstoragedefhtml_to_attachment(request_json):
storage_client=storage.Client()
bucket_name=os.environ.get("CLOUD_STORAGE_BUCKET")
bucket=storage_client.bucket(bucket_name)
blob_name=generate_random_string(12) +'.txt'blob=bucket.blob(blob_name)
text_content=html_to_text(request_json['html'])
logging.warning("html to attachment text content is: "+text_content)
blob.upload_from_string(text_content, content_type='text/text')
blob_url=f'https://storage.cloud.google.com/{bucket_name}/{blob_name}'request_json['attachments'] = [{'url': blob_url}]
returnblob_urldefbeyond_to_attachment(request_json):
"""This function is Beyond specific."""storage_client=storage.Client()
bucket_name=os.environ.get("CLOUD_STORAGE_BUCKET")
bucket=storage_client.bucket(bucket_name)
blob_name=generate_random_string(12) +'.txt'blob=bucket.blob(blob_name)
# Extract all the <a> tag textssoup=BeautifulSoup(request_json['html'], 'html.parser')
a_tags=soup.find_all('a')
a_tag_texts= [a_tag.get_text(strip=True) fora_tagina_tags]
# Find the order URL then download the ordera_tag_texts= [textfortextina_tag_textsiftextandtext.startswith('http')]
url=a_tag_texts[0]
response=requests.get(url)
html_content=response.texttext_content=html_to_text(html_content)
blob.upload_from_string(text_content, content_type='text/text')
blob_url=f'https://storage.cloud.google.com/{bucket_name}/{blob_name}'request_json['attachments'] = [{'url': blob_url}]
returnblob_urldefhtml_to_text(html_content):
# Parse the HTML contentsoup=BeautifulSoup(html_content, 'html.parser')
# Process list itemsforliinsoup.find_all('li'):
li.string=f'* {li.string}'li.insert_after('\n')
# Process tablesforrowinsoup.find_all('table'):
row.insert_before('{====\n')
row.insert_after('====}\n')
forrowinsoup.find_all('tr'):
row.insert_before('[--\n')
row.insert_after('--]\n')
forcellinsoup.find_all(['td', 'th']):
cell.insert_after('\n')
processed_text=soup.get_text(separator='\n', strip=True)
returnprocessed_textdefgenerate_random_string(length):
"""Generates a random string of the specified length. Args: length: The desired length of the random string. Returns: A random string consisting of letters and digits. """characters=string.ascii_letters+string.digitsrandom_string=''.join(random.choice(characters) for_inrange(length))
returnrandom_string`
Stack trace
`requests.exceptions.SSLError: HTTPSConnectionPool(host='storage.googleapis.com', port=443): Max retries exceeded with url: /upload/storage/v1/b/peblla-order-test/o?uploadType=multipart&ifGenerationMatch=0 (Caused by SSLError(SSLEOFError(8, '[SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1006)')))`
It worked when I used upload_from_string in the html_to_attachment function to upload the file, but when I used beyond_to_attachment to upload the file, it had problems uploading strings, which seemed to be an ssl related error
Thanks!
The text was updated successfully, but these errors were encountered:
Hi, Im getting this error since mid Mar when before it was working well.
Environment details
Code example
Stack trace
It worked when I used upload_from_string in the html_to_attachment function to upload the file, but when I used beyond_to_attachment to upload the file, it had problems uploading strings, which seemed to be an ssl related error
Thanks!
The text was updated successfully, but these errors were encountered: