*** 错误编译 './__MACOSX/._request.py' [谷歌云]

问题描述 投票:0回答:0

我正在尝试在 gcloud 中使用 Cloud Function,但出现此错误

Build failed: *** Error compiling './__MACOSX/._request.py'...

我不明白为什么我会得到这个。 (顺便说一句,我对 gcloud 很陌生)

我部署的代码是这样的>

import requests
from datetime import date
import base64
from google.cloud import storage
import json


def create_json(json_object, filename):
    '''
    this function will create json object in
    google cloud storage
    '''
    # create a blob
    blob = BUCKET.blob("raw_data/"+filename)
    # upload the blob 
    blob.upload_from_string(
        data=json.dumps(json_object),
        content_type='application/json'
        )
    result = filename + ' upload complete'
    return {'response' : type(result)}

def main():
      url = "xxx"

      payload={}

      headers = {
      'authority': 'xxx',
      'accept': '*/*',
      'accept-language': 'en-US,en;q=0.7',
      'cookie': 'xxx',
      'if-none-match': '"c9a5-KeIG0gepOCXKYXsEiIlXvqNwGh4"',
      'referer': 'https://sa.aqar.fm/%D8%B9%D9%82%D8%A7%D8%B1%D8%A7%D8%AA/1',
      'sec-ch-ua': 'xxx',
      'sec-ch-ua-mobile': 'xx',
      'sec-ch-ua-platform': '"xx"',
      'sec-fetch-dest': 'empty',
      'sec-fetch-mode': 'cors',
      'sec-fetch-site': 'same-origin',
      'sec-gpc': '1',
      'sentry-trace': 'xxx',
      'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36'
      }

      response = requests.request("GET", url, headers=headers, data=payload)
      today = date.today()

      data = response.text

    # credentials to get access google cloud storage
    # write your key path in place of gcloud_private_key.json
      storage_client = storage.Client.from_service_account_json('/projects/xxx/secrets/bucketSecret/versions/1/xxx')

    # write your bucket name in place of bucket1go
      bucket_name = 'xxx'
      BUCKET = storage_client.get_bucket(bucket_name)
      # your object
      json_object = data
    # set the filename of your json object
      filename = "data_{}.json".format(today)

    # run the function and pass the json_object
      print(create_json(json_object, filename))

很明显它与一些字符串有关,但我在我的代码中找不到任何空字符串!

需求文件

beautifulsoup4==4.11.2
bs4==0.0.1
requests==2.28.2
google-cloud-storage==1.40.0

.gcloudignore 文件

# This file specifies files that are *not* uploaded to Google Cloud Platform
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
#   $ gcloud topic gcloudignore
#
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or files
# from your .gitignore file, remove the corresponding line
# below:
.git
.gitignore
node_modules

python json google-cloud-functions httprequest gcloud
© www.soinside.com 2019 - 2024. All rights reserved.