Unexpected keyword argument “context” when using a

2019-03-17 22:12发布

I tried to update a project on Google App Engine via appcfg.py:

C:\> "C:\Program Files (x86)\Google\google_appengine\appcfg.py" update c:\secondApp

But I get the following error immediately (top lines are ignored):

File "C:\Python27\lib\urllib2.py", line 1240, in https_open
    context=self._context)
TypeError: do_open() got an unexpected keyword argument 'context'

I decided to dig into the file urllib2.py and find the problem. After a few minutes of code reviewing, I came to this conclusion that an overload accepting a parameter named context does not exist. So, I changed the original code snippet:

def https_open(self, req):
    return self.do_open(httplib.HTTPSConnection, req,
        context=self._context) 

to

def https_open(self, req):
    return self.do_open(httplib.HTTPSConnection, req)

and Voila! It works (although another problem regarding authentication arise, but the first problem get solved). But it is very strange that in an official release there exists a bug like this while is very likely other people have encountered the same problem. Surprisingly, I couldn't find this issue reported by anyone else!

Is there anything wrong in the module? Am I mixing wrong versions of installed packages? Any help?

My Google App Engine SDK Version: 1.9.17 x64

My Installed Python Version: 2.7.9 x64

My Platform: Windows 8.1 x64

and I am not familiar with Python :D

Solution:

As Migel Tissera mentioned the problem is about authentication. But I tried his proposed command and got the same error. Fortunately, I executed the following command and success! (I added --noauth_local_webserver and --no_cookies switches too):

appcfg.py --noauth_local_webserver --oauth2 --skip_sdk_update_check --no_cookies update c:\secondApp

2条回答
等我变得足够好
2楼-- · 2019-03-17 22:53

I ran in to the same problem about half an hour ago.. It's actually nothing to do with the urllib2 file, it's got something to do with the authentication. This fixed it for me..

Use appcfg.py with --oauth2 flag. Try this, appcfg.py --oauth2 update /path/to/your/app. In the first time you will see the browser window where you'll need to allow access to your account. Then you can deploy your app without entering email and password.

I hope this helps. Glad to post my first answer here! :)

Thanks, Migel

查看更多
女痞
3楼-- · 2019-03-17 23:03

This error might also occur when using an incompatible version of the Appengine SDK.

In my case upgrading the SDK fixed it.

查看更多
登录 后发表回答