请求太大错误,向App Engine发送请求

时间:2019-05-09 19:44:45

标签: python-3.x google-app-engine python-requests

我在使用Python 3运行时的App Engine Flex上有一个应用程序。我使用以下代码从Google Storage获取恢复文件的base64编码的字节字符串。

storage_client = storage.Client(project=[MYPROJECT])
bucket = storage_client.get_bucket([MYBUCKET])
blob = bucket.blob([MYKEY])
resume_file = blob.download_as_string()

resume_file = str(base64.b64encode(resume_file))[2:-1]

我将其作为请求参数的一部分发送,如下所示:

headers = {'Authorization': 'Bearer {}'.format(signed_jwt),
           'content-type': 'application/json'}

params = {'inputtype': 'file',
           'resume': resume_file}

response = requests.get(HOST, headers=headers, params=params)

但是,出现以下错误:

  

错误413(请求实体太大)

     

您的客户发出的请求太大

     

这就是我们所知道的

App Engine的文件大小限制为32MB。但是,我的文件只有24KB。如何解决此错误?

1 个答案:

答案 0 :(得分:1)

我不得不将我的应用程序更改为接受POST请求而不是GET请求。

以前,我是将简历作为参数发送的。我现在将其作为数据发送:

payload = json.dumps({
            'inputtype': inputtype,
            'resume': inputresume
          })

response = requests.post(HOST, headers=headers, data=payload)

我正在使用Flask。以前,我是使用以下方式在params中进行阅读的:

request.args.get('resume')

我将其更改为:

request.get_json().get('resume')

这是问题/答案here

的扩展