from flask import Flask, session, render_template, request, redirect, url_for
from urllib2 import Request, urlopen, HTTPError
from json import dump
import json
def checkLogin():
data = {}
data['login'] = request.form['login']
data['password'] = request.form['password']
headers = {'Content-Type': 'application/json'}
jsonData = json.dumps(data)
myRequest = Request("http://edi.iem.pw.edu.pl....", data=jsonData,
headers=headers)
try:
myResponse = urlopen(myRequest)
myResponseDict = json.load(myResponse)
if myResponse.getCode() == 200 and myResponseDict['info'] == 'OK':
session['token'] = myResponseDict['token']
session['uid'] = myResponseDict['uid']
else:
myResponseDict['error']
except HTTPError as e:
print e.code
print e.reason
return e.read()
我收到错误:“AttributeError:addinfourl实例没有属性'getCode'”
我在没有括号的情况下编写方法“getCode”时检查它是否有效但是它不起作用。
在类似的主题中,我没有得到答案,所以我有疑问在这种情况下我该怎么办?
答案 0 :(得分:1)
虽然PyCharm提示我使用getCode()方法,但我刚刚在getcode()中从上部“C”更改为“c”。