python - Django WSGIRequest.get_full_path() doesn't return the full URI -
i have wrote piece of django code "tweets" website "twitter" called weibo in china.(indeed problem nothing related task). piece of code run in local computer django test web server(started command: python manage.py runserver
).
the code piece likes these:
def authsucc(request): app_key = '5032*****' app_secret = '367362***************' callback_url = 'http://lifein.azurewebsites.net/weibo/authsucc.html' client = apiclient(app_key=app_key, app_secret=app_secret, redirect_uri=callback_url) r = client.request_access_token(request.build_absolute_uri()[-32:]) #return httpresponse(request.get_full_path()) access_token = r.access_token expires_in = r.expires_in client.set_access_token(access_token, expires_in) r = client.statuses.user_timeline.get() resp = "" st in r.statuses: resp += st.text + "<br/>" return httpresponse(resp)
but problem after deploy website on windows azure website(host on iis 8.0 webserver). function call request.get_full_path()
didn't work , return "weibo/authsucc.html" while actual request "http://lifein.azurewebsites.net/weibo/authsucc.html?code=08e69b6acb825029f4fa5af1f7ed394d" checked local var in django's debug mode. parts of it:
request "<wsgirequest\npath:/weibo/authsucc.html,\n get:<querydict: {}>,\n post:<querydict: >{}>,\n 'http_host': 'lifein.azurewebsites.net',\n 'http_x_original_url': '/weibo/authsucc.html?code=08e69b6acb825029f4fa5af1f7ed394d',\n 'iis_urlrewritemodule': '7.1.0761.0',\n 'iis_wasurlrewritten': '1',\n 'path_info': u'/weibo/authsucc.html',\n 'path_translated':'c:\\\\dwasfiles\\\\sites\\\\lifein\\\\virtualdirectory0\\\\site\\\\wwwroot\\\\handler.fcgi\\\\weibo\\\\authsucc.html',\n 'query_string': '',\n 'request_method': 'get',\n 'request_uri': '/weibo/authsucc.html?code=08e69b6acb825029f4fa5af1f7ed394d',\n 'server_software': 'microsoft-iis/8.0',\n 'unencoded_url': '/weibo/authsucc.html?code=08e69b6acb825029f4fa5af1f7ed394d',\n 'url': '/handler.fcgi',\n 'wsgi.errors': <cstringio.stringo object @ 0x010392a0>,\n 'wsgi.input': <cstringio.stringi object @ 0x012c9458>,\n 'wsgi.multiprocess': true,\n 'wsgi.multithread': false,\n 'wsgi.run_once': false,\n 'wsgi.url_scheme': 'http',\n 'wsgi.version': (1, 0)}>"
we can see 'request_uri' , 'http_x_original_url' attribute of request correctly set, querydict empty. request.get_full_path()
returns "/weibo/authsucc.html" instead of excepted "/weibo/authsucc.html?code=08e69b6acb825029f4fa5af1f7ed394d" in local server. wonder how solve problem. me?
the querystring not part of path of uri. behavior observed correct. creates new question, how full uri django.core.handlers.wsgi.wsgirequest object. logical answers seems be:
uri = '%s?%s' % (request.get_full_path, request.query_string)
though creates reconstruction not give exact uri used perform http request. example, there no way distinguish /path/ /path/? .
to determine sure it's required gain direct access raw http request. have not yet been able this. update when find working answer.
Comments
Post a Comment