私はPythonAnywhereでDjangoプロジェクトを展開しようとしています。 これまでのところ、コマンドを実行しましたPython Foursquare API Wrapper - TypeError __init __()は予期せぬキーワード引数 'clientId'を持っています
./manage.py migrate
./manage.py runserver
エラーを返しません。私のサイトに行くと、私はlocalhostから接続したときに私のホームページを見ることができます:8000
彼が望む食べ物のタイプを入力するための入力ボックスは2つあります(ピザまたはアイスクリームの例)。場所(都市を検索する)と結果が表示されます(例えばニューヨークのピザの場所)私は結果を得るためにFoursquare apiを使いました。
ローカルホストから試してみると、すべて正常に動作します。しかし、私が.pythonanywhere.comから検索しようとすると、エラーが発生します。私は何も変更していませんが、エラーはパラメータを変更しています。
エラー:
TypeError at/
__init__() got an unexpected keyword argument 'clientId'
Request Method: POST
Request URL: http://jinxed.pythonanywhere.com/
Django Version: 1.10.5
Exception Type: TypeError
Exception Value:
__init__() got an unexpected keyword argument 'clientId'
Exception Location: /home/jinxed/Foursquare-API-with-Django/indexapp/views.py in index, line 37
Python Executable: /usr/local/bin/uwsgi
Python Version: 3.4.3
Python Path:
['/var/www',
'.',
'',
'/var/www',
'/home/jinxed/.virtualenvs/mysite-virtualenv/lib/python3.4',
'/home/jinxed/.virtualenvs/mysite-virtualenv/lib/python3.4/plat-x86_64-linux-gnu',
'/home/jinxed/.virtualenvs/mysite-virtualenv/lib/python3.4/lib-dynload',
'/usr/lib/python3.4',
'/usr/lib/python3.4/plat-x86_64-linux-gnu',
'/home/jinxed/.virtualenvs/mysite-virtualenv/lib/python3.4/site-packages',
'/home/jinxed/Foursquare-API-with-Django']
Server time: Fri, 27 Jan 2017 14:20:45 +0300
、私のviews.pyは以下のとおりです。
from django.shortcuts import render
from indexapp.forms import IndexForm
from foursquare import Foursquare
from indexapp.models import Database
def index(request):
f_food = ''
f_location = ''
fs_result = []
error = ''
searched_dict = []
# check whether the parameters coming through input fields or search history panel
if request.method == 'POST': # from input fields
iForm = IndexForm(request.POST)
if iForm.is_valid():
f_food = iForm.cleaned_data['food']
f_location = iForm.cleaned_data['location']
else:
error = 'Invalid form'
elif request.GET.get('query') is not None and request.GET.get('location') is not None: # from search history panel
f_food = request.GET.get('query')
f_location = request.GET.get('location')
# if I do not get any f_food at all, that means parameters are still in their initial values
if f_food is not '':
fs = Foursquare(clientId = 'XXXXXXX',
clientSecret = 'XXXXXX',
version = '20170127')
fs.veneus(f_food, f_location)
fs_meta = fs.getMeta()
if fs_meta['code'] != 200: # meta = 200 for successful, 400 for failure
error = "Unsuccessful data"
else:
fs_result = fs.getPlaces() # this is keeping the veneus dict
d = Database(food = f_food, location = f_location) # same as the INSERT INTO
d.save()
last_twenty = Database.objects.all().order_by('-id')[:20] # take the last 20 search
searched_dict = last_twenty.values() # turn it to a array of dictionaries
# clear the searched history
if request.GET.get('delete') == '1':
Database.objects.all().delete()
return render(request, "index.html",{'error': error, 'results': fs_result,
'f_f': f_food,'f_l': f_location,
'searched_dict': searched_dict})
あなたはそのライン37は "バージョン= '20170127'"
誰もが私を助けることができる含ま見ますこの ?
はどうもありがとうございますEDITここ
は、私は名前を扱っ私foursquare.py(CLIENT_ID等。)
import requests
class Foursquare:
def __init__(self, clientId, clientSecret, version):
self.cId = clientId
self.cSecret = clientSecret
self.cVersion = version
self.results = {}
def veneus(self, q, n):
prm = {'query': q,
'near': n,
'client_id': self.cId,
'client_secret': self.cSecret,
'v': self.cVersion
}
r = requests.get('https://api.foursquare.com/v2/venues/search', params=prm)
self.results = r.json() # take it as an json object
def getPlaces(self):
return self.results['response']['venues']
def getMeta(self): # to see if we are getting the unsuccessful data
return self.results['meta']
EDITある2
ファイルのレイアウトは次のとおりです
Foursquare-API-with-Django
|
|---backend---
| |- __init__.py
| |- settings.py
| |- urls.py
| |- wsgi.py
|
|---indexapp--
| |- __init__.py
| |- admin.py
| |- apps.py
| |- forms.py
| |- foursquareT.py
| |- models.py
| |- tests.py
| |- urls.py
| |- views.py
|-- manage.py
は、あなたの代わりにclientId
とclientSecret
の、client_id
とclient_secret
を使用する必要がありますFoursquareのAPIのショーのために
Foursquareクラスは 'clientId'パラメータを取っていません。 –
しかしそれはあります。 Foursquareクラスを追加して私の質問を編集しました。 – Alexa
コードでサードパーティのライブラリではなくクラスを使用していますか? –