我正在使用:
uWSGI启动参数:
--socket 127.0.0.1:8081 --daemonize --enable-threads --threads 2 --processes 2
Run Code Online (Sandbox Code Playgroud)
我设置我的MongoClient ONE时间:
self.mongo_client = MongoClient('mongodb://user:pw@host.mongolab.com:port/mydb')
self.db = self.mongo_client['mydb']
Run Code Online (Sandbox Code Playgroud)
我尝试将一个JSON字典保存到MongoDB:
result = self.db.jobs.insert_one(job_dict)
Run Code Online (Sandbox Code Playgroud)
它通过单元测试工作,该测试执行与mongodb相同的代码路径.但是当我使用HTTP POST通过CherryPy和uWSGI执行时,我得到了这个:
pymongo.errors.ServerSelectionTimeoutError: No servers found yet
Run Code Online (Sandbox Code Playgroud)
为什么我在通过CherryPy和uWSGI运行时会看到这种行为?这可能是PyMongo 3中的新线程模型吗?
更新:
如果我通过使用CherryPy内置服务器运行没有uWSGI和nginx,那么就insert_one()
可以了.
更新1/25美国东部时间下午4:53:
在PyMongo中添加一些调试后,似乎topology._update_servers()
知道服务器'myserver-a.mongolab.com'的server_type = 2.但是server_description.known_servers()
服务器'myserver.mongolab.com'的server_type = 0
这导致以下堆栈跟踪:
result = self.db.jobs.insert_one(job_dict)
File "/usr/local/lib/python3.4/site-packages/pymongo/collection.py", line 466, in insert_one
with self._socket_for_writes() as sock_info:
File "/usr/local/lib/python3.4/contextlib.py", line 59, in __enter__
return next(self.gen)
File …
Run Code Online (Sandbox Code Playgroud) 我正在使用AWS Javascript API并尝试获取指定的cognito id:
AWS.config.credentials.get(function(err) {
if (!err) {
console.log("Cognito Identity Id: " + AWS.config.credentials.identityId);
}
});
Run Code Online (Sandbox Code Playgroud)
为什么这会导致下面的消息出现400错误?
{"__type":"InvalidIdentityPoolConfigurationException","message":"Invalid identity pool configuration. Check assigned IAM roles for this pool."}
Run Code Online (Sandbox Code Playgroud)
我为经过身份验证和未经身份验证的用户配置了IAM角色.
{
"Version": "2012-10-17",
"Statement": [{
"Action": [
"mobileanalytics:PutEvents",
"cognito-sync:*"
],
"Effect": "Allow",
"Resource": [
"*"
]
}]
}
Run Code Online (Sandbox Code Playgroud) 成功获取cognito身份后,我们再尝试获取openIdToken()
AWS.config.credentials.get(function(err) {
if (!err) {
var cognitoIdentity = new AWS.CognitoIdentity();
cognitoIdentity.getOpenIdToken({IdentityId: AWS.config.credentials.identityId}, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
} else {
console.log('cognito error: ' + err);
}
});
Run Code Online (Sandbox Code Playgroud)
但是,这失败了:
"NotAuthorizedException: Access to Identity 'us-east-1:xxxxx' is forbidden.
Run Code Online (Sandbox Code Playgroud)
完整的错误跟踪:
POST https://cognito-identity.us-east-1.amazonaws.com/ 400 (Bad Request)
aws-sdk.min.js:5 [AWS cognitoidentity 400 0.192s 0 retries] getOpenIdToken({IdentityId: 'us-east-1:xxxxx' })
routing.html:64 Error: Access to Identity 'us-east-1:xxxxx' is forbidden.
at a (https://www.example.com/bower_components/aws-sdk-js/dist/aws-sdk.min.js:6:3548)
at r.SequentialExecutor.r.util.inherit.callListeners (https://www.example.com/bower_components/aws-sdk-js/dist/aws-sdk.min.js:6:28594)
at r.SequentialExecutor.r.util.inherit.emit …
Run Code Online (Sandbox Code Playgroud)