using HTTPHandler cause Django server side shows http 400 and Invalid HTTP_HOST header message

2017-04-10 Thread Philip Lee


I also posted The question here 
http://stackoverflow.com/questions/43185804/using-httphandler-cause-django-server-side-shows-http-400-and-invalid-http-host
 


I am using HTTPHandler 
 to 
send logging messages to a Django Web server with The following code,

import loggingimport 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')

but The server side shows http 400 and Invalid HTTP_HOST header message 
like this

Invalid HTTP_HOST header: '192.168.8.100:8000,192.168.8.100'. The domain 
name pr ovided is not valid according to RFC 1034/1035. [05/Apr/2017 
10:43:14] "GET /VideoParser/lYYDownloaderClientLog/?relativeCreated 
=117.00654029846191=5468=ERROR_info=None_text=None
 
ess=8920=a.py=39.52503204345703_info=None=40
 
sName=MainProcess=testing+remote+logging=a=MainThread
 
no=26=1491360192.039525=%3Cmodule%3E=%28%29=
*main*& 
pathname=C%3A%5CUsers%5Ci%5CDocuments%5CTencent+Files%5C2281570025%5CFileRecv%5C
 
a.py HTTP/1.1" 400 68137

while request from browser with url

http://192.168.8.100:8000/VideoParser/lYYDownloaderClientLog/?filename=log55.p%20y=40=88.00482749938965=%3Cmodule%3E=7144%20_info=None=log55=%28%29_text=None=D%3A%5CBaiduYun%20Download%5C%E7%BC%96%E7%A8%8B%5CPython%5Clog55.py=ERROR=668.0548%20191070557=MainThread=6664=root=34=yahoo+Serve%20r+Exception_info=None=MainProcess=1491225161.6680548

could actually send a good request to The server , The server shows The 
following in this case

--- '], '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=40=88.00482749938965=%3Cmodule%3E=
7144%20_info=None=log55=%28%29_text=None=D%3A%5CB
aiduYun%20Download%5C%E7%BC%96%E7%A8%8B%5CPython%5Clog55.py=ERROR
s=668.0548%20191070557=MainThread=6664=root=34
g=yahoo+Serve%20r+Exception_info=None=MainProcess=149122
5161.6680548 HTTP/1.1" 200 27

so what's wrong with my code using HTTPHandler 
 to 
send logging messages to a Django Web server ?

As I have tested: If I pass the IP address of my web server to the host 
parameter of HTTPHandler, the server side would show http 400 and Invalid 
HTTP_HOST header message, there are also exceptions , pasted here 
https://bpaste.net/show/f2d2e64e7a7e , while if I pass the domain name 
instead, then the view function works as expected . so would it be a bug 
within HTTPHandler?

related code For debug

django-test\LYYDownloaderServer\VideoParser\urls.py

from django.conf.urls import urlfrom . import views
app_name = 'VideoParser'
urlpatterns = [
url(r'lYYDownloaderClientLog.+',views.lYYDownloaderClientLog, 
name='lYYDownloaderClientLog')]

django-test\LYYDownloaderServer\VideoParser\views.py

def lYYDownloaderClientLog(request):
print('---', request.GET)
return HttpResponse("")  # The server *successfully* processed the request 
and is not returning any content.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2e383515-3e78-4f6a-8681-0eb7858251f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


The Django server side shows http 400 and Invalid HTTP_HOST header message

2017-04-03 Thread Philip Lee


I am using HTTPHandler to send logging messages to a Django Web server with The 
following code, 

>
> import logging
> import logging.handlers
> logger = logging.getLogger('mylogger')
> http_handler = logging.handlers.HTTPHandler('localhost:8000', 
> '/VideoParser/lYYDownloaderClientLog')#, method='POST'
> logger.addHandler(http_handler)
> logger.error('testing remote logging')


but The server side shows http 400 and Invalid HTTP_HOST header message like 
this 

>
> Invalid HTTP_HOST header: 'localhost:8000,localhost'. The domain name 
> provided i
> s not valid according to RFC 1034/1035.
> [03/Apr/2017 19:15:41] "GET 
> /VideoParser/lYYDownloaderClientLog?filename=a.py
> readName=MainThread_info=None=MainProcess_text=None
> d=1491218139.538086=ERROR=a=3624_info=None
> reated=112.00642585754395=40=C%3A%5CUsers%5Ci%5CDocuments%5CTen
> cent+Files%5C2281570025%5CFileRecv%5Ca.py=538.0859375=testing+remote+l
> ogging=mylogger=%28%29=12=6700=%3Cmodule%3E 
> HT
> TP/1.1" 400 67823


so how to fix The issue ?

related code
django-test\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-test\LYYDownloaderServer\VideoParser\views.py

>
> def lYYDownloaderClientLog(request):
> print('---', request.GET)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/aa561085-f498-412e-9f2f-2e5af04df9a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django doesn't email reporting an internal server error (HTTP status code 500)

2016-12-28 Thread Philip Lee
Please help! The question are also posted here
http://stackoverflow.com/questions/41363888/django-doesnt-email-reporting-an-internal-server-error-http-status-code-500

I could send mail using the following code

E:\Python\django-test\LYYDownloaderServer>python manage.py shell
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (In
tel)] on win32Type "help", "copyright", "credits" or "license" for more 
information.(InteractiveConsole)>>> from django.core.mail import 
send_mail>> send_mail(... 'Subject here',... 'Here is the 
message.',... 'redstone-c...@163.com',... ['2281570...@qq.com'],... 
fail_silently=False,... )1>>> 

According to the doc 

:

When DEBUG is False, Django will email the users listed in the ADMINS 
setting whenever your code raises an unhandled exception and results in an 
internal server error (HTTP status code 500). This gives the administrators 
immediate notification of any errors. The ADMINS will get a description of 
the error, a complete Python traceback, and details about the HTTP request 
that caused the error.

but in my case, Django doesn't email reporting an internal server error 
(HTTP status code 500) [image: enter image description here] 


what's the problem? please help fix the problem


settings.py

"""
Django settings for LYYDownloaderServer project.

Generated by 'django-admin startproject' using Django 1.9.1.

For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""
import os
ADMINS = [('Philip', 'r234327...@163.com'), ('Philip2', '768799...@qq.com')]
EMAIL_HOST = 'smtp.163.com'  # 'localhost'#'smtp.139.com'# EMAIL_PORT = 25# 
EMAIL_USE_TLS = True

EMAIL_HOST_USER = 'r234327...@163.com'  # '13529123...@139.com'
EMAIL_HOST_PASSWORD = '**'# DEFAULT_FROM_EMAIL = 'r234327...@163.com'# 
Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production# See 
https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 's4(z8qzt$=x(2t(ok5bb58_!u==+x97t0vpa=*8bb_68baekkh'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = ['127.0.0.1']#, '.0letter.com'

# Application definition

INSTALLED_APPS = [
'VideoParser.apps.VideoparserConfig',
'FileHost.apps.FilehostConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',]

MIDDLEWARE_CLASSES = [
'django.middleware.common.BrokenLinkEmailsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',]

ROOT_URLCONF = 'LYYDownloaderServer.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},]

WSGI_APPLICATION = 'LYYDownloaderServer.wsgi.application'

# Database# https://docs.djangoproject.com/en/1.9/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}}

# Password validation# 
https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 
'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 
'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 
'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 
'django.contrib.auth.password_validation.NumericPasswordValidator',
},]

# Internationalization# https://docs.djangoproject.com/en/1.9/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, 

Design an encrypted time-limited API on Client/Server side

2016-06-09 Thread Philip Lee


I am planning design an encrypted time-limited API on both Client and 
Server sides, the server side is written in Django, the client side is a 
GUI program which call the API by

import requests
c = requests.post("http://127.0.0.1:8000/VideoParser/;, data={'videoUrl': 
videoUrl })

The way it call the API is desperately exposed to those who can use network 
traffic capturing tools like wireshark and fiddler, while I don't want 
anyone else could call the API with their customized videoUrl, and if 
people made the post call with the same parameters 2 minutes later after 
the client initially made the call, the call should be valid or expired, so 
how to design the encrypted time-limited API on both Client and Server side 
in this case ?
--

P.S. I think add an identifier to the post data could prevent them using 
the API

import requests
c = requests.post("http://127.0.0.1:8000/VideoParser/;, data={'videoUrl': 
videoUrl, 'identifier':value_of_identifier })

provided there is something encrypted in the value_of_identifier and it 
changes with each call, but I don't know how to get started, any idea ?

It would be better to show some code , I really don't know how to start to 
write code.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c90bd293-f44a-4916-bffa-1fae0663ed0e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.