Python 3.x TypeError:process_session()缺少1个必需的位置参数:';会议';

Python 3.x TypeError:process_session()缺少1个必需的位置参数:';会议';,python-3.x,google-cloud-platform,google-cloud-firestore,google-cloud-functions,Python 3.x,Google Cloud Platform,Google Cloud Firestore,Google Cloud Functions,我遇到了这个错误我尝试了所有的方法,我将这个函数部署为google云函数,但是当我运行触发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_

我遇到了这个错误我尝试了所有的方法,我将这个函数部署为google云函数,但是当我运行触发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

这都是def过程_会话的一部分吗?我看不见缩进。 它在类对象中吗? 也许可以试试第4行:

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

给定的错误表明您没有引用类对象。

您试图在中传递3个参数,Python只接受1个参数,其中一个参数是

HTTP函数

您的函数被传递一个参数(request),它是一个 烧瓶请求对象。从函数中返回任何可以使用的值 通过烧瓶制备响应方法进行处理。结果将是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")
或者,如果需要为入口点使用更多参数,可以使用

背景函数

后台函数是传递给 与触发函数的事件关联的数据 执行。在Python运行时中,函数被传递 参数(数据、上下文)


是的,它是def process_session process_session函数的全部组成部分。会话函数写在main.py文件中,我在google cloud上部署了这个函数我从同一个项目的另一个文件init.py复制了这个函数,因为我只需要将这个函数设为无服务器的,这是init.py文件中的类后端。我尝试了你的建议,但仍然得到相同的错误