【发布时间】:2019-10-13 18:38:20
【问题描述】:
我在谷歌云函数https://ocr.space/ocrapi上使用这个api
这是我部署的功能
def ocr_space_url(request):
request_json = request.get_json()
request_args = request.args
if request_json and 'url' in request_json:
url = request_json['url']
elif request_args and 'url' in request_args:
url = request_args['url']
else:
url = 'http://www.africau.edu/images/default/sample.pdf'
headers = {
'apikey': 'helloworld',
}
payload = {'url': url,
}
r = requests.post('https://api.ocr.space/parse/image',
headers=headers, data=payload,
)
return r.content.decode()
这样部署:gcloud functions deploy ocr_space_url --runtime python37 --trigger-http
通过以下方式调用它:curl -X POST "https://us-central1-prefab-environs-241910.cloudfunctions.net/ocr_space_url" -H "Content-Type:application/json" -d "{"url": "http://dl.a9t9.com/ocrbenchmark/pdfscan.pdf"}"
当我使用内容类型调用它时,它会给我以下错误
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>The browser (or proxy) sent a request that this server could not understand.</p>
如果我在没有内容类型的情况下调用它,它会进入 else,因为我得到 request_json = None 而对于 else 中的 url,它会给我正确的结果
我是第一次使用云功能,请帮忙
【问题讨论】:
标签: python-3.x curl flask google-cloud-platform google-cloud-functions