Sunday, October 9, 2011

Re: question : Add HTTP-GET accessabilty to 'Poll', Based on samuraisam's django-json-rpc

Dear All.
C/q Tom Evans, Thankyou for your enlightment


On 10/07/2011 05:25 PM, Tom Evans wrote:
> On Fri, Oct 7, 2011 at 6:31 AM, bino oetomo<bino@indoakses-online.com> wrote:
>
> The URL you are trying to go to does not match up with the URL you
> configured in urls.py (nor does it match up with the docs you linked
> to). Your tested URL starts with 'jsonrpc/', your urls.py says
> 'json/'.
>
> Cheers
>
> Tom
>
I Tried to re-write the application from scratch
project-name = thepoll
app-name = polls

----------Here is my "INSTALLED_APP"
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'polls',
'jsonrpc',
)
------And, Below is my main url.py ----
from django.contrib import admin
admin.autodiscover()
import thepoll.polls.views # you must import the views that need connected

urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
#Below is for JSON-RPC
url(r'^jsonrpc/browse/', 'jsonrpc.views.browse',
name="jsonrpc_browser"),
url(r'^jsonrpc/', jsonrpc_site.dispatch, name="jsonrpc_mountpoint"),
(r'^jsonrpc/(?P<method>[a-zA-Z0-9.]+)$', jsonrpc_site.dispatch),
)
------And, below is my views.py from "polls" app
from jsonrpc import jsonrpc_method
from polls.models import *


@jsonrpc_method('polls.sayhello', safe=True)
def sayhello(request, name='Lester'):
return "Hello %s" % name
========================

Next, I try to HTTP-GET access using python console :

>>> import urllib
>>> urlbase = 'http://127.0.0.1:8000/jsonrpc/polls.sayhello?'
>>> urlparam = {'name':'SAM'}
>>> urlenc = urllib.urlencode(urlparam)
>>> print urllib.urlopen(urlbase+urlenc).read()

-----And the results (from python console)
{"error": {"executable": "/usr/bin/python", "code": -32600, "name":
"InvalidRequestError", "message": "InvalidRequestError: The method you
are trying to access is not availble by GET requests", "data": null,
"stack": "Traceback (most recent call last):\n File
\"/usr/local/lib/python2.6/dist-packages/django_json_rpc-0.6.2-py2.6.egg/jsonrpc/site.py\",
line 207, in dispatch\n raise InvalidRequestError('The method you are
trying to access is '\nInvalidRequestError\n"}, "id": null, "result": null}
================

Looks like it can not find the Method (in this case : "polls.sayhello")

I made a test using it provided Mochikit graphical browser and console (
http://127.0.0.1:8000/jsonrpc/browse/ ),
----------and Got :
> >> jsonrpc.polls.sayhello('bino')
Requesting ->
{"id":"jsonrpc", "params":["bino"], "method":"polls.sayhello",
"jsonrpc":"1.0"}
Deferred(2, unfired)
Got ->
{"error": null, "jsonrpc": "1.0", "id": "jsonrpc", "result": "Hello bino"}
> >> dir(jsonrpc)
["polls"]
-------------------
So I'm sure the method is there.


Kindly please give me your enlightment to fix this.

Sincerely
-bino-

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment