2017-01-27 9 views
0

私は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       

は、あなたの代わりにclientIdclientSecretの、client_idclient_secretを使用する必要がありますFoursquareのAPIのショーのために

+1

Foursquareクラスは 'clientId'パラメータを取っていません。 –

+0

しかしそれはあります。 Foursquareクラスを追加して私の質問を編集しました。 – Alexa

+0

コードでサードパーティのライブラリではなくクラスを使用していますか? –

答えて

1

docs、ありがとうございました。

fs = Foursquare(client_id='XXXXXXX', 
       client_secret='XXXXXX', 
       version='20170127', 
) 
+0

私は、Foursquare.pyのinit関数を使ってFoursquareクラスで処理しました。あなたが私が言っていることを見ることができるように私の質問を編集しました。 – Alexa

+0

あなたが 'foursquare import Foursquare'をしたときにあなたのコードがあなたのクラスをインポートしていないように思えます。サードパーティライブラリを使用していない場合はアンインストールしてください。確かに、あなたの 'foursquare.py'の名前を' myfoursquare.py'に変更し、 'myfoursquare import Foursquare'から'を実行することができます。 – Alasdair

+0

実際、私はあなたの 'foursquare.py'を' foursquareT.py'と改名し、クラス名を 'FoursquareT'と改名したと言っただけです。もちろん、インポートセクションを 'foursquareT import FoursquareT'から変更しましたが、今は' error:no module foursquareT'というモジュールがあります – Alexa

関連する問題