Collin, thanks for the help. My django application as it is already has the 
"requests" library installed within it and I have already registered it 
with the API which I'm trying to authenticate to currently using that API's 
oauth2 web application flow, which is a three step process (see the oauth2 
tab for the  Canvas API). I'm able so far to send a redirect-uri to the 
Canvas Oauth2 api and have it respond back to me with all of the other 
information I need to get my final access token from then. My application 
currently uses Python 2.7.8 and Django 1.7 and the piece of the process 
that I'm having the problem with is sending the final POST request back to 
the Canvas Oauth2 flow API. The response that up to now I've tried to 
return back from my django view  has been an HttpResponse which apparently 
does not allow the sending of a POST request. I've also taken a look at all 
of the shortcut functions that django offers as options to return back from 
django views, and none of them appear at least not obviously to offer any 
options for sending POST requests. Your response below seems to show how I 
might get the access token back from the final POST request which I need to 
make to the Canvas Oauth2 flow. Can you show me how to do that POST, 
and what I need my view to return, to avoid getting and error which says 
that my view did  not return a valid HttpResponse but instead returned 
"None" like I've gotten up until now?
Thanks again for the help.

Henry 

On Saturday, January 17, 2015 at 7:33:40 AM UTC-6, Collin Anderson wrote:

> Hi,
>
> Use urllib/urllib2 or requests to POST to other websites. Python can do it 
> natively.
>
> try:  # Python 3
>     from urllib import request as urllib_request
> except ImportError:  # Python 2
>     import urllib2 as urllib_request
> from django.utils.http import urlencode
>
> def my_view(request):
>     response = urllib_request.urlopen('https://endpoint/', urlencode({
> 'mytoken': '12345'}))
>     data = response.read()
>     # etc
>
> https://docs.python.org/3/library/urllib.request.html
> https://docs.python.org/2/library/urllib2.html
>
> or install requests, which is friendlier:
> http://docs.python-requests.org/en/latest/
>
> Collin
>
> On Thursday, January 15, 2015 at 11:51:45 AM UTC-5, Henry Versemann wrote:
>>
>> First let me say that I haven't done a lot of stuff with either Python or 
>> Django, but I think I understand most of the basics. 
>> I am trying to get an access token back from the OAuth2 Web Application 
>> Flow of the Canvas' LMS API ( 
>> https://canvas.instructure.com/doc/api/file.oauth.html ). 
>> I have successfully sent the request in step 1 of the flow, and 
>> received back and extracted out of the response all of the data needed for 
>> step 3, which came back in step 2 of the flow.
>> So now in step 3 of the flow my problem is how to send a POST of the 
>> request needed, as described in step 3 of the flow, from a Django View.
>> I've not found anything definitive saying that I absolutely can't do 
>> a POST of a request, from a Django View, and have seen some  items which 
>> seem to indicate that I can do a POST from a view, but none of them seem to 
>> have detailed code examples or explanations of how to do it if it is 
>> possible. 
>> So far I've tried several ways of sending the POST within a 
>> returned HttpResponse and have not been successful, and if I understand 
>> things correctly HttpResponse doesn't allow it. 
>> I have also looked at all of the other Django Shortcut Functions 
>> documentation, and none of them seem to offer any obvious way of POSTing a 
>> request either. 
>> Can someone please point me to a good example of how to do it if it is 
>> possible, and if it is not maybe point me to one or more examples of how I 
>> might be able to successfully go through the Canvas OAuth2 Web Application 
>> Flow using some other module or package, that I can integrate into my 
>> Django application?
>> Thanks for the help.
>>
>

-- 
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/11c413b5-75e3-4326-aa02-f4ea9d766109%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to