中文字符作为发送get请求的get参数值

时间:2016-11-24 02:54:15

标签: python django api advanced-rest-client

我尝试通过以下网址在Advanced REST Client上发送get请求:

http://127.0.0.1:8000/report/game/?gamecategory=电子游艺

但是返回了错误:

Exception happened during processing of request from ('127.0.0.1', 51260)
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 599, in process_request_thread
    self.finish_request(request, client_address)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/Users/deanchristianarmada/Desktop/projects/jaguar/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 99, in __init__
    super(WSGIRequestHandler, self).__init__(*args, **kwargs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 655, in __init__
    self.handle()
  File "/Users/deanchristianarmada/Desktop/projects/jaguar/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 176, in handle
    self.rfile, self.wfile, self.get_stderr(), self.get_environ()
  File "/Users/deanchristianarmada/Desktop/projects/jaguar/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 150, in get_environ
    if '?' in path:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 27: ordinal not in range(128)

这不是代码,因为这是我唯一的代码:

class ReportGame(APIView):
    '''
    @brief      Game Report on Lion's new page
    '''

    permission_classes = (AllowAny, )
    model = GameAccount
    serializer = ReportGameSerializer

    def get(self, request, *args, **kwargs):
        '''
        '''

        print 'dean'
        return Response(data='data', status=status.HTTP_200_OK)

有没有办法使用我当前的网址Get参数来解决这个问题?

我正在使用:

python == 2.7.10
django-rest-framework == 3.5
django == 1.10

更新

这很奇怪,因为我试图使用python的库请求做同样的请求,它实际上工作正常

>>> url = 'http://127.0.0.1:8000/report/game/?gamecategory=电子游艺'
>>> requests.get(url)
<Response [200]>
>>> x.content
'{"members":[{"id":5,"member":"chrisguinto","bet_record_count":3,"valid_bet_amount":6.0,"bet_amount":7.0,"profit":0.0},{"id":6,"member":"deanchrisarmada","bet_record_count":2,"valid_bet_amount":8.0,"bet_amount":6.0,"profit":2.0}],"member_count":2}'

我还试过用AngularJS发送请求,但是它有效:

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">

<p>Today's welcome message is:</p>

<h1>{{myWelcome}}</h1>

</div>

<p>The $http service requests a page on the server, and the response is set as the value of the "myWelcome" variable.</p>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
  $http.get("http://127.0.0.1:8000/report/game/?gamecategory=电子游艺")
  .then(function(response) {
      $scope.myWelcome = response.data;
  });
});
</script>

</body>
</html>

**结论:** 我想这只是Advanced Rest Client的结束

0 个答案:

没有答案