Search code examples
pythonrequestresponseurllib2

AttributeError: addinfourl instance has no attribute 'getCode'


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()

I get error: "AttributeError: addinfourl instance has no attribute 'getCode'"

I check if it work when I write method "getCode" without brackets but it doesn't work.

In similar topic I didn't got the answer so I have question what can I do in this case?


Solution

  • I have just change from upper "C" to lower "c" in getcode() although PyCharm prompted me to getCode() method.