我需要的是设置在def interceptor(request)函数之外定义的头值。我怎样才能通过考试?
def randomkeklul(main_arg):
return random.choice(['kek', 'lul']), random.choice(main_arg)
def interceptor(request):
request.headers['Accept-Encoding'] = value1
request.headers['Accept-Language'] = value2
def main():
main_arg = '12345'
value1, value2 = randomkeklul(main_arg)
driver.request_interceptor = interceptor
它没有帮助https://github.com/wkeeling/selenium-wire#example-add-a-request-header它像司机一样工作。Request_interceptor =拦截器但如果我想添加参数让它看起来像
def randomkeklul(main_arg):
return random.choice(['kek', 'lul']), random.choice(main_arg)
def interceptor(request,arg1,arg2):
request.headers['Accept-Encoding'] = arg1
request.headers['Accept-Language'] = arg2
def main():
main_arg = '12345'
value1, value2 = randomkeklul(main_arg)
driver.request_interceptor = interceptor(arg1=value1, arg2=value2)
引发错误
TypeError: interceptor()缺少1个必需的位置参数:'request'
我有同样的问题。对我来说,唯一可行的方法是从其他函数/文件中获取参数:
def interceptor(request):
from custom_credentials import custom_credentials
username, password = custom_credentials()
auth_b = username + ':' + password
auth = (
base64.encodebytes(auth_b.encode())
.decode()
.strip()
)
del request.headers['Authorization']
request.headers['Authorization'] = f'Basic {auth}'