私はPythonにまったく慣れていません。Tkinterで遊んでいて、 Webアプリケーションにログインできる簡単なプログラムを作成しようとしています。次のエラーが表示されます。
Exception in Tkinter callback
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1410, in __call__
return self.func(*args)
File "test.py", line 35, in login
c.post('http://fruro.com/login.php', data=self.payload)
File "/Users/Peter/Desktop/fruroPy/fruro/lib/python2.7/site-packages/requests/sessions.py", line 399, in post
return self.request('POST', url, data=data, **kwargs)
File "/Users/Peter/Desktop/fruroPy/fruro/lib/python2.7/site-packages/requests/sessions.py", line 343, in request
prep = req.prepare()
File "/Users/Peter/Desktop/fruroPy/fruro/lib/python2.7/site-packages/requests/models.py", line 222, in prepare
p.prepare_body(self.data, self.files)
File "/Users/Peter/Desktop/fruroPy/fruro/lib/python2.7/site-packages/requests/models.py", line 375, in prepare_body
body = self._encode_params(data)
File "/Users/Peter/Desktop/fruroPy/fruro/lib/python2.7/site-packages/requests/models.py", line 81, in _encode_params
return urlencode(result, doseq=True)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 1311, in urlencode
len(v)
AttributeError: Entry instance has no attribute '__len__'
私は何時間もの間、何がうまくいかなかったのかを理解しようとしてきましたが、何が間違っているのかわかりません.
これが私が使用している私のコードです:
from Tkinter import *
from requests import session
class Login:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.emLabel = Label(frame, text="Email:")
self.emLabel.pack(side=LEFT)
self.email = Entry(frame, width=15)
self.email.pack(side=LEFT)
self.pasLabel = Label(frame, text="Password:")
self.pasLabel.pack(side=LEFT)
self.password = Entry(frame, show="*", width=15)
self.password.pack(side=LEFT)
self.hi_there = Button(frame, text="Login", command=self.login)
self.hi_there.pack()
def login(self):
self.payload = {
'action': 'login',
'email': self.email,
'password': self.password
}
with session() as c:
c.post('http://fruro.com/login.php', data=self.payload)
self.request = c.get('http://fruro.com')
print self.request.headers
print self.request.text
root = Tk()
login = Login(root)
root.title("Login to your account")
root.mainloop()
どんな助けでも大歓迎です。前もって感謝します。