Re: Sending Data from client side(another computer) to Django(my computer) using Socket library

2015-05-11 Thread Guilherme Leal
Puting plain, you just need to execute a POST request on the client side.
That makes aviable the content on the request.POST property on your client
side view.

Wich tecnology you use to make the post request doesnt matter. The only
thing you need to keep in mind is when you "navigate" through your browser,
you're making a GET request, not a POST. Thats why your request didnt had a
body on the exemple you previously provided.

If you explained a little bit more of your app context, would be easier to
explain more.

2015-05-11 10:51 GMT-03:00 steve malise :

> I want to display HTTP POST data from client side to on the server side and
> what am supposed do to achieve?
>
> On Mon, May 11, 2015 at 3:31 PM, Jani Tiainen  wrote:
>
>> Hi,
>>
>> Sounds like you're mixing up terms and technologies here and really you
>> are trying something that Django was never designed for.
>>
>> It would be really helpful to know what are you really trying to do,
>> instead of just trying techniques that may or may not work for your case.
>>
>>
>> On Mon, 11 May 2015 15:18:37 +0200
>> steve malise  wrote:
>>
>> > Meaning write JavaScript code to make a request?
>> > how can achieve it other than writing JavaScript code?
>> >
>> >
>> > On Mon, May 11, 2015 at 3:13 PM, Guilherme Leal 
>> wrote:
>> >
>> > > The "navigation" of your browser always performs a GET method. If
>> you're
>> > > trying to test that kind of request in the browser, the best aproach
>> would
>> > > be open the JavaScript and make the request there.
>> > >
>> > > 2015-05-11 10:09 GMT-03:00 steve malise :
>> > >
>> > >> client code:
>> > >> import httplib
>> > >> import urllib
>> > >>
>> > >> data = urllib.urlencode({'data':'data1'})
>> > >> conn = httplib.HTTPConnection(myipaddr)
>> > >> headers = {"Content-type":"application/x-www-form-urlencoded",
>> > >> "Accept":"text/plain",
>> > >>  "Content-Length:":len(data)}
>> > >> h.request('POST','/',data,headers)
>> > >>
>> > >> res = h.getresponse()
>> > >> print r.status,r.reason
>> > >>
>> > >> server side code(view.py):
>> > >>
>> > >> from django.shortcuts import render
>> > >> from django.views.decorators.csrf import csrf_exempt
>> > >> from django.http import HttpResponse
>> > >> from django.conf.urls import url
>> > >> from django.template import loader
>> > >> from django.utils.timezone import utc
>> > >> from django.template import Context, Template
>> > >> from django.template.loader import get_template
>> > >> from django.shortcuts import render_to_response
>> > >> from django.template import RequestContext
>> > >> from myapp.models import Temperature
>> > >> from myapp import models
>> > >> import socket , select
>> > >> import os
>> > >> import datetime
>> > >> socktetList=[]
>> > >>
>> > >>
>> > >> @csrf_exempt
>> > >> def myview(request):
>> > >> if request.method == 'POST':
>> > >> return HttpResponse("%s %s" % (request.method, request.body))
>> > >> #print POST body
>> > >> else:
>> > >> return HttpResponse("%s %s" % (request.method, request.body))
>> > >>
>> > >> on the client side i get "200 OK"(everything is ok)
>> > >> but when i open my browser it return "GET",
>> > >>
>> > >> i want it to return or display POST DATA.
>> > >>
>> > >> how can i do that??
>> > >> please help
>> > >>
>> > >>
>> > >>
>> > >> On Thu, May 7, 2015 at 4:13 PM, Thomas Levine <_...@thomaslevine.com>
>> wrote:
>> > >>
>> > >>> On 07 May 16:00, steve malise wrote:
>> > >>> > The error comes when i runserver and send data from another
>> computer to
>> > >>> > django,then i get this "code 400, message Bad request syntax (
>> data
>> > >>> from
>> > >>> > another computer)"
>> > >>>
>> > >>> This is because
>> > >>>
>> > >>> On 07 May 11:42, Tom Evans wrote:
>> > >>> > Eurgh. Your hand-crafted HTTP request is not a valid request. Use
>> one
>> > >>> > of the http libraries built in to python:
>> > >>>
>> > >>> You can find here some directions on forming the request validly,
>> > >>> http://www.w3.org/Protocols/Specs.html
>> > >>>
>> > >>> as you apparently don't want to use any of the libraries below.
>> > >>>
>> > >>> On 07 May 16:00, steve malise wrote:
>> > >>> > urllib2:
>> > >>> > https://docs.python.org/2/howto/urllib2.html#data
>> > >>> >
>> > >>> > httplib:
>> > >>> > https://docs.python.org/2/library/httplib.html#examples
>> > >>> >
>> > >>> > or use a 3rd party library that wraps those in a more pleasing
>> > >>> interface:
>> > >>> >
>> > >>> > requests:
>> > >>> > http://docs.python-requests.org/en/latest/
>> > >>>
>> > >>> Using one of the above-listed libraries would still accomplish what
>> you
>> > >>> are trying to do, as you described here,
>> > >>>
>> > >>> On 07 May 16:00, steve malise wrote:
>> > >>> > What i am trying to do is run python script(client side) on
>> another
>> > >>> > computer which is on same network with my computer,then 

Re: Sending Data from client side(another computer) to Django(my computer) using Socket library

2015-05-11 Thread steve malise
I want to display HTTP POST data from client side to on the server side and
what am supposed do to achieve?

On Mon, May 11, 2015 at 3:31 PM, Jani Tiainen  wrote:

> Hi,
>
> Sounds like you're mixing up terms and technologies here and really you
> are trying something that Django was never designed for.
>
> It would be really helpful to know what are you really trying to do,
> instead of just trying techniques that may or may not work for your case.
>
>
> On Mon, 11 May 2015 15:18:37 +0200
> steve malise  wrote:
>
> > Meaning write JavaScript code to make a request?
> > how can achieve it other than writing JavaScript code?
> >
> >
> > On Mon, May 11, 2015 at 3:13 PM, Guilherme Leal 
> wrote:
> >
> > > The "navigation" of your browser always performs a GET method. If
> you're
> > > trying to test that kind of request in the browser, the best aproach
> would
> > > be open the JavaScript and make the request there.
> > >
> > > 2015-05-11 10:09 GMT-03:00 steve malise :
> > >
> > >> client code:
> > >> import httplib
> > >> import urllib
> > >>
> > >> data = urllib.urlencode({'data':'data1'})
> > >> conn = httplib.HTTPConnection(myipaddr)
> > >> headers = {"Content-type":"application/x-www-form-urlencoded",
> > >> "Accept":"text/plain",
> > >>  "Content-Length:":len(data)}
> > >> h.request('POST','/',data,headers)
> > >>
> > >> res = h.getresponse()
> > >> print r.status,r.reason
> > >>
> > >> server side code(view.py):
> > >>
> > >> from django.shortcuts import render
> > >> from django.views.decorators.csrf import csrf_exempt
> > >> from django.http import HttpResponse
> > >> from django.conf.urls import url
> > >> from django.template import loader
> > >> from django.utils.timezone import utc
> > >> from django.template import Context, Template
> > >> from django.template.loader import get_template
> > >> from django.shortcuts import render_to_response
> > >> from django.template import RequestContext
> > >> from myapp.models import Temperature
> > >> from myapp import models
> > >> import socket , select
> > >> import os
> > >> import datetime
> > >> socktetList=[]
> > >>
> > >>
> > >> @csrf_exempt
> > >> def myview(request):
> > >> if request.method == 'POST':
> > >> return HttpResponse("%s %s" % (request.method, request.body))
> > >> #print POST body
> > >> else:
> > >> return HttpResponse("%s %s" % (request.method, request.body))
> > >>
> > >> on the client side i get "200 OK"(everything is ok)
> > >> but when i open my browser it return "GET",
> > >>
> > >> i want it to return or display POST DATA.
> > >>
> > >> how can i do that??
> > >> please help
> > >>
> > >>
> > >>
> > >> On Thu, May 7, 2015 at 4:13 PM, Thomas Levine <_...@thomaslevine.com>
> wrote:
> > >>
> > >>> On 07 May 16:00, steve malise wrote:
> > >>> > The error comes when i runserver and send data from another
> computer to
> > >>> > django,then i get this "code 400, message Bad request syntax ( data
> > >>> from
> > >>> > another computer)"
> > >>>
> > >>> This is because
> > >>>
> > >>> On 07 May 11:42, Tom Evans wrote:
> > >>> > Eurgh. Your hand-crafted HTTP request is not a valid request. Use
> one
> > >>> > of the http libraries built in to python:
> > >>>
> > >>> You can find here some directions on forming the request validly,
> > >>> http://www.w3.org/Protocols/Specs.html
> > >>>
> > >>> as you apparently don't want to use any of the libraries below.
> > >>>
> > >>> On 07 May 16:00, steve malise wrote:
> > >>> > urllib2:
> > >>> > https://docs.python.org/2/howto/urllib2.html#data
> > >>> >
> > >>> > httplib:
> > >>> > https://docs.python.org/2/library/httplib.html#examples
> > >>> >
> > >>> > or use a 3rd party library that wraps those in a more pleasing
> > >>> interface:
> > >>> >
> > >>> > requests:
> > >>> > http://docs.python-requests.org/en/latest/
> > >>>
> > >>> Using one of the above-listed libraries would still accomplish what
> you
> > >>> are trying to do, as you described here,
> > >>>
> > >>> On 07 May 16:00, steve malise wrote:
> > >>> > What i am trying to do is run python script(client side) on another
> > >>> > computer which is on same network with my computer,then receive
> data
> > >>> from
> > >>> > another computer with the django(which is running on my
> computer(server
> > >>> > side)).i am using built-in "runserver".
> > >>>
> > >>> so I suspect that you are doing something more that we missed.
> Perhaps
> > >>> you could tell us why you want to do this?
> > >>>
> > >>> --
> > >>> 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 

Re: Sending Data from client side(another computer) to Django(my computer) using Socket library

2015-05-11 Thread Jani Tiainen
Hi,

Sounds like you're mixing up terms and technologies here and really you are 
trying something that Django was never designed for.

It would be really helpful to know what are you really trying to do, instead of 
just trying techniques that may or may not work for your case.


On Mon, 11 May 2015 15:18:37 +0200
steve malise  wrote:

> Meaning write JavaScript code to make a request?
> how can achieve it other than writing JavaScript code?
> 
> 
> On Mon, May 11, 2015 at 3:13 PM, Guilherme Leal  wrote:
> 
> > The "navigation" of your browser always performs a GET method. If you're
> > trying to test that kind of request in the browser, the best aproach would
> > be open the JavaScript and make the request there.
> >
> > 2015-05-11 10:09 GMT-03:00 steve malise :
> >
> >> client code:
> >> import httplib
> >> import urllib
> >>
> >> data = urllib.urlencode({'data':'data1'})
> >> conn = httplib.HTTPConnection(myipaddr)
> >> headers = {"Content-type":"application/x-www-form-urlencoded",
> >> "Accept":"text/plain",
> >>  "Content-Length:":len(data)}
> >> h.request('POST','/',data,headers)
> >>
> >> res = h.getresponse()
> >> print r.status,r.reason
> >>
> >> server side code(view.py):
> >>
> >> from django.shortcuts import render
> >> from django.views.decorators.csrf import csrf_exempt
> >> from django.http import HttpResponse
> >> from django.conf.urls import url
> >> from django.template import loader
> >> from django.utils.timezone import utc
> >> from django.template import Context, Template
> >> from django.template.loader import get_template
> >> from django.shortcuts import render_to_response
> >> from django.template import RequestContext
> >> from myapp.models import Temperature
> >> from myapp import models
> >> import socket , select
> >> import os
> >> import datetime
> >> socktetList=[]
> >>
> >>
> >> @csrf_exempt
> >> def myview(request):
> >> if request.method == 'POST':
> >> return HttpResponse("%s %s" % (request.method, request.body))
> >> #print POST body
> >> else:
> >> return HttpResponse("%s %s" % (request.method, request.body))
> >>
> >> on the client side i get "200 OK"(everything is ok)
> >> but when i open my browser it return "GET",
> >>
> >> i want it to return or display POST DATA.
> >>
> >> how can i do that??
> >> please help
> >>
> >>
> >>
> >> On Thu, May 7, 2015 at 4:13 PM, Thomas Levine <_...@thomaslevine.com> 
> >> wrote:
> >>
> >>> On 07 May 16:00, steve malise wrote:
> >>> > The error comes when i runserver and send data from another computer to
> >>> > django,then i get this "code 400, message Bad request syntax ( data
> >>> from
> >>> > another computer)"
> >>>
> >>> This is because
> >>>
> >>> On 07 May 11:42, Tom Evans wrote:
> >>> > Eurgh. Your hand-crafted HTTP request is not a valid request. Use one
> >>> > of the http libraries built in to python:
> >>>
> >>> You can find here some directions on forming the request validly,
> >>> http://www.w3.org/Protocols/Specs.html
> >>>
> >>> as you apparently don't want to use any of the libraries below.
> >>>
> >>> On 07 May 16:00, steve malise wrote:
> >>> > urllib2:
> >>> > https://docs.python.org/2/howto/urllib2.html#data
> >>> >
> >>> > httplib:
> >>> > https://docs.python.org/2/library/httplib.html#examples
> >>> >
> >>> > or use a 3rd party library that wraps those in a more pleasing
> >>> interface:
> >>> >
> >>> > requests:
> >>> > http://docs.python-requests.org/en/latest/
> >>>
> >>> Using one of the above-listed libraries would still accomplish what you
> >>> are trying to do, as you described here,
> >>>
> >>> On 07 May 16:00, steve malise wrote:
> >>> > What i am trying to do is run python script(client side) on another
> >>> > computer which is on same network with my computer,then receive data
> >>> from
> >>> > another computer with the django(which is running on my computer(server
> >>> > side)).i am using built-in "runserver".
> >>>
> >>> so I suspect that you are doing something more that we missed. Perhaps
> >>> you could tell us why you want to do this?
> >>>
> >>> --
> >>> 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 http://groups.google.com/group/django-users.
> >>> To view this discussion on the web visit
> >>> https://groups.google.com/d/msgid/django-users/20150507141332.GA27942%40d1stkfactory
> >>> .
> >>> For more options, visit https://groups.google.com/d/optout.
> >>>
> >>
> >>  --
> >> 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 

Re: Sending Data from client side(another computer) to Django(my computer) using Socket library

2015-05-11 Thread Guilherme Leal
Just to clarify, in your browser, if you simply "navigate" to the url of
your view, the browser will issue a GET to the server.

If you write the JavaScript function, you can specify the method of your
request... preaty much the same thing as you did in the exemple that you
sent.

Its fairly trivial, and JQuery makes it even simpler
.



2015-05-11 10:18 GMT-03:00 steve malise :

> Meaning write JavaScript code to make a request?
> how can achieve it other than writing JavaScript code?
>
>
> On Mon, May 11, 2015 at 3:13 PM, Guilherme Leal 
> wrote:
>
>> The "navigation" of your browser always performs a GET method. If you're
>> trying to test that kind of request in the browser, the best aproach would
>> be open the JavaScript and make the request there.
>>
>> 2015-05-11 10:09 GMT-03:00 steve malise :
>>
>>> client code:
>>> import httplib
>>> import urllib
>>>
>>> data = urllib.urlencode({'data':'data1'})
>>> conn = httplib.HTTPConnection(myipaddr)
>>> headers = {"Content-type":"application/x-www-form-urlencoded",
>>> "Accept":"text/plain",
>>>  "Content-Length:":len(data)}
>>> h.request('POST','/',data,headers)
>>>
>>> res = h.getresponse()
>>> print r.status,r.reason
>>>
>>> server side code(view.py):
>>>
>>> from django.shortcuts import render
>>> from django.views.decorators.csrf import csrf_exempt
>>> from django.http import HttpResponse
>>> from django.conf.urls import url
>>> from django.template import loader
>>> from django.utils.timezone import utc
>>> from django.template import Context, Template
>>> from django.template.loader import get_template
>>> from django.shortcuts import render_to_response
>>> from django.template import RequestContext
>>> from myapp.models import Temperature
>>> from myapp import models
>>> import socket , select
>>> import os
>>> import datetime
>>> socktetList=[]
>>>
>>>
>>> @csrf_exempt
>>> def myview(request):
>>> if request.method == 'POST':
>>> return HttpResponse("%s %s" % (request.method, request.body))
>>> #print POST body
>>> else:
>>> return HttpResponse("%s %s" % (request.method, request.body))
>>>
>>> on the client side i get "200 OK"(everything is ok)
>>> but when i open my browser it return "GET",
>>>
>>> i want it to return or display POST DATA.
>>>
>>> how can i do that??
>>> please help
>>>
>>>
>>>
>>> On Thu, May 7, 2015 at 4:13 PM, Thomas Levine <_...@thomaslevine.com>
>>> wrote:
>>>
 On 07 May 16:00, steve malise wrote:
 > The error comes when i runserver and send data from another computer
 to
 > django,then i get this "code 400, message Bad request syntax ( data
 from
 > another computer)"

 This is because

 On 07 May 11:42, Tom Evans wrote:
 > Eurgh. Your hand-crafted HTTP request is not a valid request. Use one
 > of the http libraries built in to python:

 You can find here some directions on forming the request validly,
 http://www.w3.org/Protocols/Specs.html

 as you apparently don't want to use any of the libraries below.

 On 07 May 16:00, steve malise wrote:
 > urllib2:
 > https://docs.python.org/2/howto/urllib2.html#data
 >
 > httplib:
 > https://docs.python.org/2/library/httplib.html#examples
 >
 > or use a 3rd party library that wraps those in a more pleasing
 interface:
 >
 > requests:
 > http://docs.python-requests.org/en/latest/

 Using one of the above-listed libraries would still accomplish what you
 are trying to do, as you described here,

 On 07 May 16:00, steve malise wrote:
 > What i am trying to do is run python script(client side) on another
 > computer which is on same network with my computer,then receive data
 from
 > another computer with the django(which is running on my
 computer(server
 > side)).i am using built-in "runserver".

 so I suspect that you are doing something more that we missed. Perhaps
 you could tell us why you want to do this?

 --
 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 http://groups.google.com/group/django-users.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/20150507141332.GA27942%40d1stkfactory
 .
 For more options, visit https://groups.google.com/d/optout.

>>>
>>>  --
>>> 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.

Re: Sending Data from client side(another computer) to Django(my computer) using Socket library

2015-05-11 Thread steve malise
Meaning write JavaScript code to make a request?
how can achieve it other than writing JavaScript code?


On Mon, May 11, 2015 at 3:13 PM, Guilherme Leal  wrote:

> The "navigation" of your browser always performs a GET method. If you're
> trying to test that kind of request in the browser, the best aproach would
> be open the JavaScript and make the request there.
>
> 2015-05-11 10:09 GMT-03:00 steve malise :
>
>> client code:
>> import httplib
>> import urllib
>>
>> data = urllib.urlencode({'data':'data1'})
>> conn = httplib.HTTPConnection(myipaddr)
>> headers = {"Content-type":"application/x-www-form-urlencoded",
>> "Accept":"text/plain",
>>  "Content-Length:":len(data)}
>> h.request('POST','/',data,headers)
>>
>> res = h.getresponse()
>> print r.status,r.reason
>>
>> server side code(view.py):
>>
>> from django.shortcuts import render
>> from django.views.decorators.csrf import csrf_exempt
>> from django.http import HttpResponse
>> from django.conf.urls import url
>> from django.template import loader
>> from django.utils.timezone import utc
>> from django.template import Context, Template
>> from django.template.loader import get_template
>> from django.shortcuts import render_to_response
>> from django.template import RequestContext
>> from myapp.models import Temperature
>> from myapp import models
>> import socket , select
>> import os
>> import datetime
>> socktetList=[]
>>
>>
>> @csrf_exempt
>> def myview(request):
>> if request.method == 'POST':
>> return HttpResponse("%s %s" % (request.method, request.body))
>> #print POST body
>> else:
>> return HttpResponse("%s %s" % (request.method, request.body))
>>
>> on the client side i get "200 OK"(everything is ok)
>> but when i open my browser it return "GET",
>>
>> i want it to return or display POST DATA.
>>
>> how can i do that??
>> please help
>>
>>
>>
>> On Thu, May 7, 2015 at 4:13 PM, Thomas Levine <_...@thomaslevine.com> wrote:
>>
>>> On 07 May 16:00, steve malise wrote:
>>> > The error comes when i runserver and send data from another computer to
>>> > django,then i get this "code 400, message Bad request syntax ( data
>>> from
>>> > another computer)"
>>>
>>> This is because
>>>
>>> On 07 May 11:42, Tom Evans wrote:
>>> > Eurgh. Your hand-crafted HTTP request is not a valid request. Use one
>>> > of the http libraries built in to python:
>>>
>>> You can find here some directions on forming the request validly,
>>> http://www.w3.org/Protocols/Specs.html
>>>
>>> as you apparently don't want to use any of the libraries below.
>>>
>>> On 07 May 16:00, steve malise wrote:
>>> > urllib2:
>>> > https://docs.python.org/2/howto/urllib2.html#data
>>> >
>>> > httplib:
>>> > https://docs.python.org/2/library/httplib.html#examples
>>> >
>>> > or use a 3rd party library that wraps those in a more pleasing
>>> interface:
>>> >
>>> > requests:
>>> > http://docs.python-requests.org/en/latest/
>>>
>>> Using one of the above-listed libraries would still accomplish what you
>>> are trying to do, as you described here,
>>>
>>> On 07 May 16:00, steve malise wrote:
>>> > What i am trying to do is run python script(client side) on another
>>> > computer which is on same network with my computer,then receive data
>>> from
>>> > another computer with the django(which is running on my computer(server
>>> > side)).i am using built-in "runserver".
>>>
>>> so I suspect that you are doing something more that we missed. Perhaps
>>> you could tell us why you want to do this?
>>>
>>> --
>>> 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 http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/20150507141332.GA27942%40d1stkfactory
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>  --
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CACwh%3D0zjAYKjmyTJTWcucTyLM_iVaLokcgqREZpXgzp7e_GEGw%40mail.gmail.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> You received this message because you are 

Re: Sending Data from client side(another computer) to Django(my computer) using Socket library

2015-05-11 Thread Guilherme Leal
The "navigation" of your browser always performs a GET method. If you're
trying to test that kind of request in the browser, the best aproach would
be open the JavaScript and make the request there.

2015-05-11 10:09 GMT-03:00 steve malise :

> client code:
> import httplib
> import urllib
>
> data = urllib.urlencode({'data':'data1'})
> conn = httplib.HTTPConnection(myipaddr)
> headers = {"Content-type":"application/x-www-form-urlencoded",
> "Accept":"text/plain",
>  "Content-Length:":len(data)}
> h.request('POST','/',data,headers)
>
> res = h.getresponse()
> print r.status,r.reason
>
> server side code(view.py):
>
> from django.shortcuts import render
> from django.views.decorators.csrf import csrf_exempt
> from django.http import HttpResponse
> from django.conf.urls import url
> from django.template import loader
> from django.utils.timezone import utc
> from django.template import Context, Template
> from django.template.loader import get_template
> from django.shortcuts import render_to_response
> from django.template import RequestContext
> from myapp.models import Temperature
> from myapp import models
> import socket , select
> import os
> import datetime
> socktetList=[]
>
>
> @csrf_exempt
> def myview(request):
> if request.method == 'POST':
> return HttpResponse("%s %s" % (request.method, request.body))
> #print POST body
> else:
> return HttpResponse("%s %s" % (request.method, request.body))
>
> on the client side i get "200 OK"(everything is ok)
> but when i open my browser it return "GET",
>
> i want it to return or display POST DATA.
>
> how can i do that??
> please help
>
>
>
> On Thu, May 7, 2015 at 4:13 PM, Thomas Levine <_...@thomaslevine.com> wrote:
>
>> On 07 May 16:00, steve malise wrote:
>> > The error comes when i runserver and send data from another computer to
>> > django,then i get this "code 400, message Bad request syntax ( data from
>> > another computer)"
>>
>> This is because
>>
>> On 07 May 11:42, Tom Evans wrote:
>> > Eurgh. Your hand-crafted HTTP request is not a valid request. Use one
>> > of the http libraries built in to python:
>>
>> You can find here some directions on forming the request validly,
>> http://www.w3.org/Protocols/Specs.html
>>
>> as you apparently don't want to use any of the libraries below.
>>
>> On 07 May 16:00, steve malise wrote:
>> > urllib2:
>> > https://docs.python.org/2/howto/urllib2.html#data
>> >
>> > httplib:
>> > https://docs.python.org/2/library/httplib.html#examples
>> >
>> > or use a 3rd party library that wraps those in a more pleasing
>> interface:
>> >
>> > requests:
>> > http://docs.python-requests.org/en/latest/
>>
>> Using one of the above-listed libraries would still accomplish what you
>> are trying to do, as you described here,
>>
>> On 07 May 16:00, steve malise wrote:
>> > What i am trying to do is run python script(client side) on another
>> > computer which is on same network with my computer,then receive data
>> from
>> > another computer with the django(which is running on my computer(server
>> > side)).i am using built-in "runserver".
>>
>> so I suspect that you are doing something more that we missed. Perhaps
>> you could tell us why you want to do this?
>>
>> --
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/20150507141332.GA27942%40d1stkfactory
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CACwh%3D0zjAYKjmyTJTWcucTyLM_iVaLokcgqREZpXgzp7e_GEGw%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 http://groups.google.com/group/django-users.
To view this 

Re: Sending Data from client side(another computer) to Django(my computer) using Socket library

2015-05-11 Thread steve malise
client code:
import httplib
import urllib

data = urllib.urlencode({'data':'data1'})
conn = httplib.HTTPConnection(myipaddr)
headers = {"Content-type":"application/x-www-form-urlencoded",
"Accept":"text/plain",
 "Content-Length:":len(data)}
h.request('POST','/',data,headers)

res = h.getresponse()
print r.status,r.reason

server side code(view.py):

from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse
from django.conf.urls import url
from django.template import loader
from django.utils.timezone import utc
from django.template import Context, Template
from django.template.loader import get_template
from django.shortcuts import render_to_response
from django.template import RequestContext
from myapp.models import Temperature
from myapp import models
import socket , select
import os
import datetime
socktetList=[]


@csrf_exempt
def myview(request):
if request.method == 'POST':
return HttpResponse("%s %s" % (request.method, request.body))
#print POST body
else:
return HttpResponse("%s %s" % (request.method, request.body))

on the client side i get "200 OK"(everything is ok)
but when i open my browser it return "GET",

i want it to return or display POST DATA.

how can i do that??
please help



On Thu, May 7, 2015 at 4:13 PM, Thomas Levine <_...@thomaslevine.com> wrote:

> On 07 May 16:00, steve malise wrote:
> > The error comes when i runserver and send data from another computer to
> > django,then i get this "code 400, message Bad request syntax ( data from
> > another computer)"
>
> This is because
>
> On 07 May 11:42, Tom Evans wrote:
> > Eurgh. Your hand-crafted HTTP request is not a valid request. Use one
> > of the http libraries built in to python:
>
> You can find here some directions on forming the request validly,
> http://www.w3.org/Protocols/Specs.html
>
> as you apparently don't want to use any of the libraries below.
>
> On 07 May 16:00, steve malise wrote:
> > urllib2:
> > https://docs.python.org/2/howto/urllib2.html#data
> >
> > httplib:
> > https://docs.python.org/2/library/httplib.html#examples
> >
> > or use a 3rd party library that wraps those in a more pleasing interface:
> >
> > requests:
> > http://docs.python-requests.org/en/latest/
>
> Using one of the above-listed libraries would still accomplish what you
> are trying to do, as you described here,
>
> On 07 May 16:00, steve malise wrote:
> > What i am trying to do is run python script(client side) on another
> > computer which is on same network with my computer,then receive data from
> > another computer with the django(which is running on my computer(server
> > side)).i am using built-in "runserver".
>
> so I suspect that you are doing something more that we missed. Perhaps
> you could tell us why you want to do this?
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/20150507141332.GA27942%40d1stkfactory
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACwh%3D0zjAYKjmyTJTWcucTyLM_iVaLokcgqREZpXgzp7e_GEGw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Sending Data from client side(another computer) to Django(my computer) using Socket library

2015-05-07 Thread Thomas Levine
On 07 May 16:00, steve malise wrote:
> The error comes when i runserver and send data from another computer to
> django,then i get this "code 400, message Bad request syntax ( data from
> another computer)"

This is because

On 07 May 11:42, Tom Evans wrote:
> Eurgh. Your hand-crafted HTTP request is not a valid request. Use one
> of the http libraries built in to python:

You can find here some directions on forming the request validly, 
http://www.w3.org/Protocols/Specs.html

as you apparently don't want to use any of the libraries below.

On 07 May 16:00, steve malise wrote:
> urllib2:
> https://docs.python.org/2/howto/urllib2.html#data
> 
> httplib:
> https://docs.python.org/2/library/httplib.html#examples
> 
> or use a 3rd party library that wraps those in a more pleasing interface:
> 
> requests:
> http://docs.python-requests.org/en/latest/

Using one of the above-listed libraries would still accomplish what you
are trying to do, as you described here,

On 07 May 16:00, steve malise wrote:
> What i am trying to do is run python script(client side) on another
> computer which is on same network with my computer,then receive data from
> another computer with the django(which is running on my computer(server
> side)).i am using built-in "runserver".

so I suspect that you are doing something more that we missed. Perhaps
you could tell us why you want to do this?

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20150507141332.GA27942%40d1stkfactory.
For more options, visit https://groups.google.com/d/optout.


Re: Sending Data from client side(another computer) to Django(my computer) using Socket library

2015-05-07 Thread steve malise
What i am trying to do is run python script(client side) on another
computer which is on same network with my computer,then receive data from
another computer with the django(which is running on my computer(server
side)).i am using built-in "runserver".

The error comes when i runserver and send data from another computer to
django,then i get this "code 400, message Bad request syntax ( data from
another computer)"



On Thu, May 7, 2015 at 3:28 PM, Tom Evans  wrote:

> On Thu, May 7, 2015 at 12:48 PM, steve malise 
> wrote:
> > where can i write web server?
> >
>
> Why do you want to?
>
> Django is a web application, it is hosted inside webservers, typically
> using WSGI. Typically, you would use one of the many webservers that
> can host wsgi applications - nginx, apache+mod_wsgi, uwsgi, chaussette
> and many many others. You can also use the built-in "runserver"
> webserver for development.
>
> If you want to write your own webserver for your own edification, the
> wsgiref library is built in to python to provide a reference
> implementation.
>
> Cheers
>
> Tom
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAFHbX1LKc_%2BBW_8JakpFLPOiZ%2BM07YwemFTZ1AH%2Bmk_TH8j42g%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACwh%3D0xQumBtV0BkWj0pqDdy8v7ZKyGU4oh9m2uXkuWoJJCbEw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Sending Data from client side(another computer) to Django(my computer) using Socket library

2015-05-07 Thread Tom Evans
On Thu, May 7, 2015 at 3:00 PM, steve malise  wrote:
> What i am trying to do is run python script(client side) on another computer
> which is on same network with my computer,then receive data from another
> computer with the django(which is running on my computer(server side)).i am
> using built-in "runserver".
>
> The error comes when i runserver and send data from another computer to
> django,then i get this "code 400, message Bad request syntax ( data from
> another computer)"
>

Write a simple django view like this:

  def myview(request):
return HttpResponse(request.raw_post_data)

In your client python script, use one of the libraries I mentioned, eg requests:

  import requests
  req = requests.post('http://hostname/url', data='hello world')
  print req.text

Go from there..

Cheers

Tom

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1K0Heb94TcrWRo-yEsf%2BM04bMWRKH-rLRasreWrJEr21A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Sending Data from client side(another computer) to Django(my computer) using Socket library

2015-05-07 Thread Tom Evans
On Thu, May 7, 2015 at 12:48 PM, steve malise  wrote:
> where can i write web server?
>

Why do you want to?

Django is a web application, it is hosted inside webservers, typically
using WSGI. Typically, you would use one of the many webservers that
can host wsgi applications - nginx, apache+mod_wsgi, uwsgi, chaussette
and many many others. You can also use the built-in "runserver"
webserver for development.

If you want to write your own webserver for your own edification, the
wsgiref library is built in to python to provide a reference
implementation.

Cheers

Tom

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1LKc_%2BBW_8JakpFLPOiZ%2BM07YwemFTZ1AH%2Bmk_TH8j42g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Sending Data from client side(another computer) to Django(my computer) using Socket library

2015-05-07 Thread steve malise
where can i write web server?


On Thu, May 7, 2015 at 12:42 PM, Tom Evans  wrote:

> On Thu, May 7, 2015 at 9:24 AM, steve malise  wrote:
> >
> > client side code:
> > data = "message"
> > try:
> > clsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> > clsocket.connect(('192.168.2.2', 8000))
> > print("Connection has been Made")
> > clsocket.send("POST / HTTP/1.1 "+ data)
> > clsocket.close()
> > except:
> > print("ERROR:Connection is not established")
>
> Eurgh. Your hand-crafted HTTP request is not a valid request. Use one
> of the http libraries built in to python:
>
> urllib2:
> https://docs.python.org/2/howto/urllib2.html#data
>
> httplib:
> https://docs.python.org/2/library/httplib.html#examples
>
> or use a 3rd party library that wraps those in a more pleasing interface:
>
> requests:
> http://docs.python-requests.org/en/latest/
>
> >
> > Django code(view.py)
> >
> > def RandomValues(request):
> >
> > template = get_template('TIME TABLE.html')
> > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> > s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
> > try:
> > s.bind(('192.168.2.2',8000))
> > s.listen(5)
> > socketList.append(s)
> > except:
> > return HttpResponse("Unable to bind ")
> >
> >
> >
> > while 1:
> > readyToread,readyTowrite,inError =
> select.select(socketList,[],[],1)
> > for sock in readyToread:
> >
> >  if sock == s:
> >   sockfd, addr = s.accept()
> >socketList.append(sockfd)
> >   else:
> >data = sock.recv(4096)
> >message = data.decode("utf-8")
> >
> > return HttpResponse(message)
>
> ?
>
> Why are you writing a webserver inside a view?
>
> Cheers
>
> Tom
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAFHbX1%2BS_w9zCk_Af5wMXZABFM%3D6k40nRWfp9P1gonsT5BNDFQ%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACwh%3D0w7X_YndLs4DJugQFw7DTmGpf9c-RcLR6sUMHQ0%2BNZscw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Sending Data from client side(another computer) to Django(my computer) using Socket library

2015-05-07 Thread Tom Evans
On Thu, May 7, 2015 at 9:24 AM, steve malise  wrote:
>
> client side code:
> data = "message"
> try:
> clsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> clsocket.connect(('192.168.2.2', 8000))
> print("Connection has been Made")
> clsocket.send("POST / HTTP/1.1 "+ data)
> clsocket.close()
> except:
> print("ERROR:Connection is not established")

Eurgh. Your hand-crafted HTTP request is not a valid request. Use one
of the http libraries built in to python:

urllib2:
https://docs.python.org/2/howto/urllib2.html#data

httplib:
https://docs.python.org/2/library/httplib.html#examples

or use a 3rd party library that wraps those in a more pleasing interface:

requests:
http://docs.python-requests.org/en/latest/

>
> Django code(view.py)
>
> def RandomValues(request):
>
> template = get_template('TIME TABLE.html')
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
> try:
> s.bind(('192.168.2.2',8000))
> s.listen(5)
> socketList.append(s)
> except:
> return HttpResponse("Unable to bind ")
>
>
>
> while 1:
> readyToread,readyTowrite,inError = select.select(socketList,[],[],1)
> for sock in readyToread:
>
>  if sock == s:
>   sockfd, addr = s.accept()
>socketList.append(sockfd)
>   else:
>data = sock.recv(4096)
>message = data.decode("utf-8")
>
> return HttpResponse(message)

?

Why are you writing a webserver inside a view?

Cheers

Tom

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1%2BS_w9zCk_Af5wMXZABFM%3D6k40nRWfp9P1gonsT5BNDFQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Sending Data from client side(another computer) to Django(my computer) using Socket library

2015-05-07 Thread steve malise

client side code:
data = "message"
try:
clsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clsocket.connect(('192.168.2.2', 8000))
print("Connection has been Made")
clsocket.send("POST / HTTP/1.1 "+ data)
clsocket.close()   
except:
print("ERROR:Connection is not established")

Django code(view.py)

def RandomValues(request):

template = get_template('TIME TABLE.html')
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
try:
s.bind(('192.168.2.2',8000))
s.listen(5)
socketList.append(s)
except:
return HttpResponse("Unable to bind ")



while 1:
readyToread,readyTowrite,inError = select.select(socketList,[],[],1)
for sock in readyToread:
  
 if sock == s:
  sockfd, addr = s.accept()
   socketList.append(sockfd)
  else:
   data = sock.recv(4096)
   message = data.decode("utf-8")

return HttpResponse(message)

On my command prompt it says:
[07/May/2015 10:06:21]code 400, message Bad request syntax ('POST / 
HTTP/1.1 message')
[07/May/2015 10:06:21]"POST / HTTP/1.1 message" 400 -

Even if i remove "POST / HTTP/1.1",i still get this error 

please help i am new to Django 



-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/12ab40fa-b80f-4f35-ab5a-75530e9eca03%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.