AttributeError: 'NoneType' object has no attribute 'split' 报错处理

报错场景

social_django 组件对原生 django 的支持较好, 但是因为 在此DRF进行的验证为 JWT 方式 和 django 的验证存在区别, 

因此需要进行更改自行支持 JWT 方式的验证信息的加入

AttributeError: 'NoneType' object has no attribute 'split' 报错处理_第1张图片

更改后再验证第三方登录时发生如下报错

详细报错

[29/Apr/2019 15:12:02] "GET / HTTP/1.1" 200 6992
[29/Apr/2019 15:12:11] "GET /login/weibo/ HTTP/1.1" 302 0
[29/Apr/2019 15:12:13] "GET /complete/weibo/?state=cpNja8cxhyV9GPSKvjVfWnwogNskNjob&code=ba1e4f6fd32f32d0b57094eecd0e7d1b HTTP/1.1" 302 0
Traceback (most recent call last):
  File "C:\Python36\lib\wsgiref\handlers.py", line 138, in run
    self.finish_response()
  File "C:\Python36\lib\wsgiref\handlers.py", line 180, in finish_response
    self.write(data)
  File "C:\Python36\lib\wsgiref\handlers.py", line 274, in write
    self.send_headers()
  File "C:\Python36\lib\wsgiref\handlers.py", line 333, in send_headers
    self._write(bytes(self.headers))
  File "C:\Python36\lib\wsgiref\headers.py", line 142, in __bytes__
    return str(self).encode('iso-8859-1')
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 251-253: ordinal not in range(256)
[29/Apr/2019 15:12:13] "GET /complete/weibo/?state=cpNja8cxhyV9GPSKvjVfWnwogNskNjob&code=ba1e4f6fd32f32d0b57094eecd0e7d1b HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 11977)
Traceback (most recent call last):
  File "C:\Python36\lib\wsgiref\handlers.py", line 138, in run
    self.finish_response()
  File "C:\Python36\lib\wsgiref\handlers.py", line 180, in finish_response
    self.write(data)
  File "C:\Python36\lib\wsgiref\handlers.py", line 274, in write
    self.send_headers()
  File "C:\Python36\lib\wsgiref\handlers.py", line 333, in send_headers
    self._write(bytes(self.headers))
  File "C:\Python36\lib\wsgiref\headers.py", line 142, in __bytes__
    return str(self).encode('iso-8859-1')
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 251-253: ordinal not in range(256)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python36\lib\wsgiref\handlers.py", line 141, in run
    self.handle_error()
  File "C:\Python36\lib\site-packages\django\core\servers\basehttp.py", line 88, in handle_error
    super(ServerHandler, self).handle_error()
  File "C:\Python36\lib\wsgiref\handlers.py", line 368, in handle_error
    self.finish_response()
  File "C:\Python36\lib\wsgiref\handlers.py", line 180, in finish_response
    self.write(data)
  File "C:\Python36\lib\wsgiref\handlers.py", line 274, in write
    self.send_headers()
  File "C:\Python36\lib\wsgiref\handlers.py", line 331, in send_headers
    if not self.origin_server or self.client_is_modern():
  File "C:\Python36\lib\wsgiref\handlers.py", line 344, in client_is_modern
    return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python36\lib\socketserver.py", line 639, in process_request_thread
    self.finish_request(request, client_address)
  File "C:\Python36\lib\socketserver.py", line 361, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Python36\lib\socketserver.py", line 696, in __init__
    self.handle()
  File "C:\Python36\lib\site-packages\django\core\servers\basehttp.py", line 155, in handle
    handler.run(self.server.get_app())
  File "C:\Python36\lib\wsgiref\handlers.py", line 144, in run
    self.close()
  File "C:\Python36\lib\wsgiref\simple_server.py", line 35, in close
    self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
----------------------------------------

解决方式

姑且这样子可以解决, 但是不知道这样会不会造成不好的影响

AttributeError: 'NoneType' object has no attribute 'split' 报错处理_第2张图片

 

转载于:https://www.cnblogs.com/shijieli/p/10791247.html

你可能感兴趣的:(AttributeError: 'NoneType' object has no attribute 'split' 报错处理)