类型错误:process_session() 缺少 1 个必需的位置参数:"会话"



我面临这个错误,我尝试了一切,我部署这个功能作为谷歌云功能,但当我运行触发URL时,我得到一个错误

请求无法处理

日志

TypeError: process_session() missing 1 required positional argument: 'session'
at call_user_function (/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v2.py:261)
at invoke_user_function (/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v2.py:268)
at run_http_function (/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v2.py:402)

函数代码

def process_session(self, session, utc_offset=0):
s = {}
try:
edfbyte, analysis = process_session(session, utc_offset)
report_json, quality = process_analysis(analysis, session.ref.id)
# save the EDF
path = 'Users/' + session.ref.get("uid") + '/session-' + session.ref.get("sessionId") + '.edf'
path_report = 'Users/' + session.ref.get("uid") + '/session-' + session.ref.get("sessionId") + '.json'
bucket = storage.bucket("......")
bucket.blob(path).upload_from_string(edfbyte, content_type='application/octet-stream')
bucket.blob(path_report).upload_from_string(report_json, content_type='application/json')
# update session
s = session.to_dict()
s[u'macid'] = analysis['header']['macid']
s[u'quality'] = quality
s[u'edfPath'] = path
s[u'reportPath'] = path_report
s[u'timestamp'] = dateutil.parser.parse(analysis['header']['startdate'])
self.db.collection(u'ProcessedSessions').document(session.ref.id).set(s)
try:
self.db.collection(u'UnprocessedSessions').document(session.ref.id).delete()
#session.ref.reference.delete()
except:
pass

return True, 0
except Exception as e:
traceback.print_exc()
s = session.to_dict()
if u'attempt' in s:
attempt = s['attempt']
else:
attempt = 0
self.db.collection(u'UnprocessedSessions').document(session.ref.id).set({u'attempt': attempt + 1}, merge=True)
return False, attempt + 1

你试图在HTTP触发器中传递3个参数,Python只接受一个Flask Request Object参数。

HTTP功能你的函数被传递了一个参数(request),它是一个Flask Request对象。返回函数中可以的任何值由Flask的make_response方法处理。结果将是HTTP响应。

你可以试着调用你的函数:

def functionx (request):
# the GCF always receive only 1 paramater an HTTP request object (flask request)
# you need to get the parameter from the request
# after that you can call your method
process_session(param1,param2,param3)

def process_session(self, session, utc_offset=0):
#dosomenthing
print ("some code here")

或者如果你需要为你的入口点使用更多的参数,你可以使用Background函数。

背景功能

后台函数传递参数保存与触发函数的事件相关联的数据执行。在Python运行时中,函数被传递给参数(data, context)

这都是def process_session的一部分吗?我看不到缩进。它在类对象中吗?也许可以试试第4行:

edfbyte, analysis = self.process_session(session, utc_offset)

给出的错误表示没有引用类对象。

最新更新