我使用HTTPHandler到日志记录消息发送到与下面的代码一个Django Web服务器,使用HttpHandler的原因Django的服务器侧示出了HTTP 400和无效HTTP_HOST标头消息
import logging
import logging.handlers
logger = logging.getLogger(__name__)
_TARGET = '192.168.8.100:8000'
_PATH = '/VideoParser/lYYDownloaderClientLog/'
sh = logging.handlers.HTTPHandler(_TARGET, _PATH)
logger.addHandler(sh)
logger.error('testing remote logging')
但服务器侧示出了HTTP 400和如此无效的HTTP_HOST标头消息
无效的HTTP_HOST标头:'192.168.8.100:8000,192.168.8.100'。根据RFC 1034/1035,提供的 域名无效。 [05 /月/ 2017年10点43分十四秒]“GET /VideoParser/lYYDownloaderClientLog /?relativeCreated = 117.00654029846191 &螺纹= 5468 & levelname = ERROR & exc_info =无& exc_text =无& PROC ESS = 8920 &文件名= a.py &毫秒= 39.52503204345703 & stack_info =无& levelno = 40个& PROCES SNAME = MainProcess &味精=试验+ +远程登录&模块=一个& threadName = MainThread &线 没有= 26 &创建= 1491360192.039525 &了funcName =%3Cmodule%3E & ARGS =%28%29 &名称= 主 & 路径名= C%3A%5CUsers%5 Cl%5CDocuments%5CTencent +文件%5C2281570025%5CFileRecv%5C 一个。 PY HTTP/1.1" 400 68137
而来自浏览器的请求使用URL
实际上可以发送一个很好的请求到服务器,服务器显示了在这种情况下,以下
----666666666666--- <QueryDict: {'stack_info': ['None'], 'levelno': ['40'], 'arg
s': ['()'], 'exc_info': ['None'], 'created': ['1491225161.6680548'], 'process':
['6664'], 'levelname': ['ERROR'], 'exc_text': ['None'], 'module': ['log55'], 'ms
ecs': ['668.0548 191070557'], 'name': ['root'], 'processName': ['MainProcess'],
'lineno': ['34'], 'thread': ['7144 '], 'msg': ['yahoo Serve r Exception'], 'func
Name': ['<module>'], 'threadName': ['MainThread'], 'filename': ['log55.p y'], 'p
athname': ['D:\\BaiduYun Download\\编程\\Python\\log55.py'], 'relativeCreated':
['88.00482749938965']}>
[05/Apr/2017 10:45:26] "GET /VideoParser/lYYDownloaderClientLog/?filename=log55.
p%20y&levelno=40&relativeCreated=88.00482749938965&funcName=%3Cmodule%3E&thread=
7144%20&stack_info=None&module=log55&args=%28%29&exc_text=None&pathname=D%3A%5CB
aiduYun%20Download%5C%E7%BC%96%E7%A8%8B%5CPython%5Clog55.py&levelname=ERROR&msec
s=668.0548%20191070557&threadName=MainThread&process=6664&name=root&lineno=34&ms
g=yahoo+Serve%20r+Exception&exc_info=None&processName=MainProcess&created=149122
5161.6680548 HTTP/1.1" 200 27
有啥错误使用HTTPHandler到日志信息发送到Django的Web服务器我的代码?
正如我测试过的:如果我将Web服务器的IP地址传递给HTTPHandler的主机参数,服务器端将显示http 400和Invalid HTTP_HOST标头消息,也有例外,这里粘贴https://bpaste.net/show/f2d2e64e7a7e,如果我传递域名,然后视图函数按预期工作。 那么它会成为HTTPHandler中的一个错误?
相关的代码进行调试
Django的测试\ LYYDownloaderServer \ VideoParser \ urls.py
from django.conf.urls import url
from . import views
app_name = 'VideoParser'
urlpatterns = [
url(r'lYYDownloaderClientLog.+',views.lYYDownloaderClientLog, name='lYYDownloaderClientLog')
]
Django的测试\ LYYDownloaderServer \ VideoParser \ views.py
def lYYDownloaderClientLog(request):
print('----666666666666---', request.GET)
return HttpResponse("") # The server *successfully* processed the request and is not returning any content.
貌似域名是错误的。你输入正确吗? –
@LeonardoChirivì对不起,我这次更新了相应的服务器消息。 – iMath
是192.168.8.100加入allowed_host? –