python3之request用法_如何扩展python3 BaseHTTPRequestHandler类,以便可以使用成员variab调用函数...

在尝试扩展Python3的BaseHTTPRequestHandler时遇到问题,错误显示为NameError,提示'Event_dictionary_list'未定义。代码中,成员变量被传给自由函数fruit_handler,但在处理POST请求时引发异常。当发送包含特定JSON格式的POST请求时,服务器无法正确处理该请求。目前不清楚导致错误的具体原因。
摘要由CSDN通过智能技术生成

我试图用我自己的成员变量扩展BaseHTTPRequestHandler。我将这些成员变量传递给自由函数,但当我这样做时,我得到:Exception happened during processing of request from ('127.0.0.1', 30006)

Traceback (most recent call last):

File "c:\Python37\lib\socketserver.py", line 313, in _handle_request_noblock

self.process_request(request, client_address)

File "c:\Python37\lib\socketserver.py", line 344, in process_request

self.finish_request(request, client_address)

File "c:\Python37\lib\socketserver.py", line 357, in finish_request

self.RequestHandlerClass(request, client_address, self)

File "fruiterer.py", line 41, in __init__

BaseHTTPRequestHandler.__init__(self, *args, **kwargs)

File "c:\Python37\lib\socketserver.py", line 712, in __init__

self.handle()

File "c:\Python37\lib\http\server.py", line 426, in handle

self.handle_one_request()

File "c:\Python37\lib\http\server.py", line 414, in handle_one_request

method()

File "fruiterer.py", line 62, in do_POST

fruit_handler(val, Event_dictionary_list, cached_timestamp)

NameError: name 'Event_dictionary_list' is not defined

下面是python3的源代码:

^{pr2}$

这可以通过在POST正文中发送以下json格式来测试:{"fruit":{"timestamp":1538688902037,"name":"apple","colour":"red","weight":100}}

我做错什么了?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值