尽管在使用GCP功能GUI进行测试时该功能可以完美运行,但我的函数中始终出现此错误。我用于在线测试的输入形式为{“ url”:“ URL_STRING”}。
我的python代码如下:
from datetime import datetime
from time import time, mktime
import pytz
import os
from os import path
import nltk
root = os.path.dirname(path.abspath(__file__))
download_dir = os.path.join(root,'my_nltk_dir')
os.chdir(download_dir)
nltk.data.load(
os.path.join(download_dir,'tokenizers/punkt/english.pickle')
)
nltk.data.load(
os.path.join(download_dir,'tokenizers/punkt/PY3/english.pickle')
)
// WORKAROUND TO REDUCE DEADLINE ERROR MARGINALLY
def Parser(url):
if 'String1' in url:
source = 'string1'
elif 'String2' in url:
source = 'string2'
elif 'String3' in url:
source = 'string3'
elif 'String4' in url:
source = 'string4'
<PARSING CODE FOR DATETIME, IMG, SOURCE, KEYWORDS>
return jsonify(source, datetime, imageurl,keywords)
def invoke_parse(request):
request_json = request.get_json(silent=True)
file = Parser(request_json['url'])
return file
我的Flutter函数调用使用cloud_functions依赖项,如下所示:
onPressed: () async {
//------------------FUNCTION CALL---------------------------------------------
final HttpsCallable callable = CloudFunctions(region:"region")
.getHttpsCallable(functionName: "function name",)..timeout = const Duration(seconds: 540);
// MASSIVE TIMEOUT TO PREVENT DEADLINE ERROR WHICH STILL HAPPENS AT ROUGHLY 10 SECS
try {
dynamic response = await callable.call(<String, dynamic>{
'url': urlController.text,
});
setState(() {
print(response.data.toString());
print(publishedAt_en = DateTime.now().toString());
});
} on CloudFunctionsException catch (e) {
print('Caught Firebase Functions Exception');
print(e.code);
print(e.message);
print(e.details);
} catch (e) {
print('Caught Generic Exception');
print(e.code);
print(e.message);
print(e.details);
}
}
请告知-感谢您的帮助。