我想问一下,使用Google App Engine BulkLoader类导入数据需要使用哪种凭据
appcfg.py upload_data --config_file=models.py --filename=listcountries.csv --kind=CMSCountry --url=http://localhost:8178/remote_api vit/
然后它要求我提供证书:
请输入localhost的登录凭据
这是一个models.py内容的提取,我使用这个listcountries.csv文件
class CMSCountry(db.Model): sortorder = db.StringProperty() name = db.StringProperty(required=True) formalname = db.StringProperty() type = db.StringProperty() subtype = db.StringProperty() sovereignt = db.StringProperty() capital = db.StringProperty() currencycode = db.StringProperty() currencyname = db.StringProperty() telephonecode = db.StringProperty() lettercode = db.StringProperty() lettercode2 = db.StringProperty() number = db.StringProperty() countrycode = db.StringProperty() class CMSCountryLoader(bulkloader.Loader): def __init__(self): bulkloader.Loader.__init__(self, 'CMSCountry', [('sortorder', str), ('name', str), ('formalname', str), ('type', str), ('subtype', str), ('sovereignt', str), ('capital', str), ('currencycode', str), ('currencyname', str), ('telephonecode', str), ('lettercode', str), ('lettercode2', str), ('number', str), ('countrycode', str) ]) loaders = [CMSCountryLoader]
每次尝试输入电子邮件和密码都会导致"身份验证失败",因此我无法将数据导入开发服务器.
我不认为我的文件和我的模型都没有任何问题,因为我已成功将数据上传到appspot.com应用程序.
那么我应该为localhost凭据添加什么?
我也尝试使用Eclipse与Pydev,但我仍然得到相同的消息:(
这是输出:
Uploading data records. [INFO ] Logging to bulkloader-log-20090820.121659 [INFO ] Opening database: bulkloader-progress-20090820.121659.sql3 [INFO ] [Thread-1] WorkerThread: started [INFO ] [Thread-2] WorkerThread: started [INFO ] [Thread-3] WorkerThread: started [INFO ] [Thread-4] WorkerThread: started [INFO ] [Thread-5] WorkerThread: started [INFO ] [Thread-6] WorkerThread: started [INFO ] [Thread-7] WorkerThread: started [INFO ] [Thread-8] WorkerThread: started [INFO ] [Thread-9] WorkerThread: started [INFO ] [Thread-10] WorkerThread: started Password for foobar@nowhere.com: [DEBUG ] Configuring remote_api. url_path = /remote_api, servername = localhost:8178 [DEBUG ] Bulkloader using app_id: abc [INFO ] Connecting to /remote_api [ERROR ] Exception during authentication Traceback (most recent call last): File "D:\Projects\GoogleAppEngine\google_appengine\google\appengine\tools\bulkloader.py", line 2802, in Run request_manager.Authenticate() File "D:\Projects\GoogleAppEngine\google_appengine\google\appengine\tools\bulkloader.py", line 1126, in Authenticate remote_api_stub.MaybeInvokeAuthentication() File "D:\Projects\GoogleAppEngine\google_appengine\google\appengine\ext\remote_api\remote_api_stub.py", line 488, in MaybeInvokeAuthentication datastore_stub._server.Send(datastore_stub._path, payload=None) File "D:\Projects\GoogleAppEngine\google_appengine\google\appengine\tools\appengine_rpc.py", line 344, in Send f = self.opener.open(req) File "C:\Python25\lib\urllib2.py", line 381, in open response = self._open(req, data) File "C:\Python25\lib\urllib2.py", line 399, in _open '_open', req) File "C:\Python25\lib\urllib2.py", line 360, in _call_chain result = func(*args) File "C:\Python25\lib\urllib2.py", line 1107, in http_open return self.do_open(httplib.HTTPConnection, req) File "C:\Python25\lib\urllib2.py", line 1082, in do_open raise URLError(err) URLError:[INFO ] Authentication Failed
谢谢!
EUREKA:我找到了使用该bulkloader.py
工具的方法,而无需手动输入登录凭据.
以下是两个步骤:
设置您的app.yaml
文件.例:
- url: /remote_api script: $PYTHON_LIB/google/appengine/ext/remote_api/handler.py login: admin
你应该把它放在你的- url: .*
线路之前app.yaml
,否则你永远不会访问/remote_api
网址.
请注意,我已经离开了login: admin
部分,因为删除它是一种非常糟糕的做法,因为您可能将其部署到生产中......
2启动此命令(根据您的需要进行调整).
echo 'XX' | python2.5 ../google_appengine/bulkloader.py --dump --kind=NAMEOFMODEL --url=http://localhost:8080/remote_api --filename=FILENAME --app_id=APPID --email=foobar@nowhere.com --passin .
诀窍是使用这两个参数的组合:
--email=
(您可以使用您想要的任何电子邮件地址,我使用foobar@nowhere.com
)
--passin
指定--email=
将禁止"输入凭据"提示,并--passin
允许从stdin
(即echo 'XX' |
发挥作用的位置)读取密码!
请享用!
PS:不要忘记投票,这样Google就可以提供一种更容易使用的方式:问题2440.