具有urlopen中的变量的Django错误400

时间:2019-01-25 09:38:06

标签: python django python-3.x

我的Django应用出现500错误,打开调试模式时出现400错误代码。我使用Python 3.5

关于这个:

token = FacebookToken.objects.get(id=1).token

url = "https://graph.facebook.com/v3.2/lamontagnesolitaire?access_token="+str(token)+"&fields=posts{id}"

fb_query = urlopen(url).read().decode('utf-8')

查询工作正常,因为当我将“令牌”作为纯字符串放置时,我没有任何错误,并且可以正确读取URL。

我已经尝试过此方法或某些变体:

url = "https://graph.facebook.com/v3.2/lamontagnesolitaire?access_token=%s&fields=posts{id}" %token

fb_query = urlopen(url).read().decode('utf-8')

我仍然收到400错误消息。

“ token”变量返回了一个好变量:

token = 'EAAIgMT9IUZBIBAI7hKtwxZCIydOeAuZCr4ddw4aGRIZCvDJHQtt2yuGYRtZBAZBGK9LsMcZAGG3VFLRQVOQU2mGkL[....]'

我的模特:

class FacebookToken(models.Model):
    token = models.CharField(max_length=300, null=False, verbose_name="Token")

Django Traceback:

Environment:


Request Method: POST
Request URL: http://localhost:9000/api/likes

Django Version: 1.11.4
Python Version: 3.5.3
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'widget_tweaks',
 'ckeditor',
 'ckeditor_uploader',
 'start',
 'myaccount',
 'wall',
 'api',
 'gunicorn',
 'django.contrib.sites',
 'django.contrib.sitemaps',
 'compressor']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "/home/django-project/seigneurdesanneaux/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
  41.             response = get_response(request)

File "/home/django-project/seigneurdesanneaux/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "/home/django-project/seigneurdesanneaux/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/django-project/seigneurdesanneaux/api/views.py" in view_likes_synchronization
  48.               fb_query = urlopen(url)

File "/usr/lib/python3.5/urllib/request.py" in urlopen
  163.     return opener.open(url, data, timeout)

File "/usr/lib/python3.5/urllib/request.py" in open
  472.             response = meth(req, response)

File "/usr/lib/python3.5/urllib/request.py" in http_response
  582.                 'http', request, response, code, msg, hdrs)

File "/usr/lib/python3.5/urllib/request.py" in error
  510.             return self._call_chain(*args)

File "/usr/lib/python3.5/urllib/request.py" in _call_chain
  444.             result = func(*args)

File "/usr/lib/python3.5/urllib/request.py" in http_error_default
  590.         raise HTTPError(req.full_url, code, msg, hdrs, fp)

Exception Type: HTTPError at /api/likes
Exception Value: HTTP Error 400: Bad Request

0 个答案:

没有答案