I am trying to build Django rest framework with MongoDB. So in my local its working. But in production, i'm using MongoLab as DB backend. But i'm not able make DB connection. I'm keep on getting DB connection authentication error.
command SON([('authenticate', 1), ('user', u'XXXXX'), ('nonce', u'XXXXX'), ('key', u'XXXXXX')]) failed: auth failed
Connection establishment code in settings file:
MONGODB_DATABASES = {
"name": "XXXXX",
"host": "XXX.mlab.com",
"port": 33212,
"username": "XXXX",
"password": "XXXX"
}
mongoengine.connect(
db=MONGODB_DATABASES['name'],
host=MONGODB_DATABASES['host'],
port=MONGODB_DATABASES['port'],
username=MONGODB_DATABASES['username'],
password=MONGODB_DATABASES['password'],
)
The MongoLab mongo version : mongod version: 3.6.6 (MMAPv1). Correct me what i did wrong
I solved the issue by connecting the mongoengine with mLab like this
mongoengine.connect(
"DB-Name",
host="mongodb://username:password#XXXXX.mlab.com:33252/db-name"
)
Thanks Micheal J Roberts
Related
I've deployed a tensorflow multi-label classification model using a sagemaker endpoint as follows:
predictor = sagemaker_model.deploy(initial_instance_count=1, instance_type="ml.m5.2xlarge", endpoint_name='testing-2')
It gets deployed and works fine when I invoke it from the Sagemaker Jupyter instance:
sample = ['this movie was extremely good']
output=predictor.predict(sample)
output:
{'predictions': [[0.00370046496,
4.32942124e-06,
0.00080883503,
9.25126587e-05,
0.00023958087,
0.000130862]]}
However, I am unable to send a request to the deployed endpoint from other notebooks or sagemaker studio. I'm unsure of the request format.
I've tried several variations in the input format and still failed. The error message is as below:
sagemaker error
Request:
{
"body": {
"text": "Testing model's prediction on this text"
},
"contentType": "application/json",
"endpointName": "testing-2",
"customURL": "",
"customHeaders": [
{
"Key": "sm_endpoint_name",
"Value": "testing-2"
}
]
}
Error:
Error invoking endpoint: Received client error (400) from primary with message "{ "error": "Failed to process element:
0 key: text of 'instances' list. Error: INVALID_ARGUMENT: JSON object: does not have named input: text" }".
See https://us-west-2.console.aws.amazon.com/cloudwatch/home?region=us-west-2#logEventViewer:group=/aws/sagemaker/Endpoints/testing-2
in account 793433463428 for more information.
Is there any way to find out exactly how the model expects the request format to be?
Earlier I had the same model on my local system and the way I tested it was using this curl request:
curl -s -H 'Content-Type: application/json' -d '{"text": "what ugly posts"}' http://localhost:7070/sentiment
And it worked fine without any issues.
I've tried different formats and replaced the "text" key inside body with other words like "input", "body", nothing etc.
Based on your description above, I assume you are deploying the TensorFlow model using the SageMaker TensorFlow container.
If you want to view what your model expects as input you can use the saved_model CLI:
1
├── keras_metadata.pb
├── saved_model.pb
└── variables
├── variables.data-00000-of-00001
└── variables.index
!saved_model_cli show --all --dir {"1"}
After you have confirmed the input name above you can invoke the endpoint as follows:
import json
import boto3
client = boto3.client('runtime.sagemaker')
data = {"instances": ['this movie was extremely good']}
response = client.invoke_endpoint(EndpointName=<EndpointName>,
Body=json.dumps(data))
response_body = response['Body']
print(response_body.read())
The same payload can then also be used in Studio when invoking the endpoint.
I am trying to connect to AWS DocumentDB with Node.js/Typescript and Mongoose. I have an EC2 instance setup as SSL tunnel, which works great. I can connect to DocumentDB locally with Studio3T and mongo-cli.
This command works mongo --sslAllowInvalidHostnames --ssl --sslCAFile rds-combined-ca-bundle.pem --username <username> --password <password>
But if I try to connect to the same database with Mongoose, it fails. This is my code and the error:
const options = {
dbName: "prodDB",
user: connectionData.username,
pass: connectionData.password,
tls: true,
tlsCAFile: "../rds-combined-ca-bundle.pem",
tlsAllowInvalidHostNames: true,
};
try {
await connect("mongodb://localhost:27017", options);
} catch (error) {
console.log(error);
}
MongooseServerSelectionError: connect EHOSTUNREACH imagine-ip-address-here:27017
reason: TopologyDescription {
type: 'ReplicaSetNoPrimary',
servers: Map(1) {
'censored:27017' => [ServerDescription]
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: 'rs0',
commonWireVersion: 7,
logicalSessionTimeoutMinutes: undefined
}
At this point, I have tried pretty much any possible config in Mongoose and I am getting desperate. Any help is appreciated
This seems to be an issue with mongoose versions >= 6.
Downgrading Mongoose to version 5.13.8 works without a problem.
Mongoose devs are apparently aware of this issue: https://github.com/Automattic/mongoose/issues/11105
I used the python code below to create a port-forwarding session.
But it seems like the session is getting terminated in a few minutes? Can anyone tell me if I am missing something here.
My target is to bind a remote port (80) to a local port (8888).
self._session_parameters = {
"Target": self._instance_id,
"DocumentName": "AWS-StartPortForwardingSession",
"Parameters": {"portNumber"[str(self._remote_port)],
"localPortNumber":[str(self._remote_port)]}
self._response = self._ssm.start_session(
Target=self._session_parameters["Target"],
DocumentName=self._session_parameters["DocumentName"],
Parameters=self._session_parameters["Parameters"])
logger.info("Received response: %s", self._response["SessionId"])
self._session_id, self._token_value = (
self._response["SessionId"],
self._response["TokenValue"])
I'm running uwsgi inside a Docker container for a Django application. I want to log uwsgi, request, and django logs differently, so I created the following configuration in my .ini file.
[uwsgi]
logger = main file:/dev/stdout
logger = django file:/dev/stdout
logger = req file:/dev/stdout
log-format = "method": "%(method)", "uri": "%(uri)", "proto": "%(proto)", "status": %(status), "referer": "%(referer)", "user_agent": "%(uagent)", "remote_addr": "%(addr)", "http_host": "%(host)", "pid": %(pid), "worker_id": %(wid), "core": %(core), "async_switches": %(switches), "io_errors": %(ioerr), "rq_size": %(cl), "rs_time_ms": %(msecs), "rs_size": %(size), "rs_header_size": %(hsize), "rs_header_count": %(headers), "event": "uwsgi_request"
log-route = main ^((?!django).)*$
log-route = django django
log-route = req uwsgi_request
log-encoder = format:django ${msg}
log-encoder = nl:django
log-encoder = json:main {"timestamp": "${strftime:%%Y-%%m-%%dT%%H:%%M:%%S+00:00Z}", "message":"${msg}","severity": "INFO"}
log-encoder = nl:main
log-encoder = format:req {"timestamp": "${strftime:%%Y-%%m-%%dT%%H:%%M:%%S}", ${msg}}
log-encoder = nl:req
The problem is that now my logs for my django and req don't show up. I'm guessing that's because multiple loggers want to write to /dev/stdout and can't.
How can I 1. Write everything to stdout while 2. Formatting my logs differently based on a regex?
I confirmed this is the case by turning of some of the log routes and seeing everything work.
Hello I'm new in postgreSQL,Please guide me a bit
I have a django project
here is settings.py :
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": "testfor_psl",
"USER": "",
"PASSWORD": "",
"HOST": "localhost",
"PORT": "",
}
}
And I run python manage.py syncdb
There is error:
OperationalError: FATAL: database "testfor_psl" does not exist
So how can I create db??
I use posgreSQL.app, and click the Open psql
There is a terminal like this :
I type help,and nothing happen.
Please help me. Thanks
You need to put ; at the end of psql commad. As you can see, after command
winsome=# CREATE DATABASE testfor_psl
the prompt is changed from =# to -#. It means, that psql still wait for the command to be completed by providing ;.
Also, it is better to create a database user for django project. So here what you need to do:
Create user in database (in psql):
CREATE USER testfor_psl_user WITH password 'pass';
Create database with owner equals to that user:
CREATE DATABASE testfor_psl ENCODING 'UTF8' TEMPLATE template0 OWNER testfor_psl_user;
Set credentials in django project settings:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": "testfor_psl",
"USER": "testfor_psl_user",
"PASSWORD": "pass",
"HOST": "localhost",
"PORT": "5432", # default port
}
}
The reason help had no effect is that you were already in the middle of writing a command. SQL commands must be terminated by a semicolon. Pay attention to the psql prompt - see how it changed from =# to -#? That indicates you're in the middle of a command. See In psql, why do some commands have no effect? .
If you weren't halfway though a command, typing help would've shown:
mydbname=> help
You are using psql, the command-line interface to PostgreSQL.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
Now... here's the manual for the psql command.
For summary help on psql its self use \? .
For a listing of SQL commands use \h.
For help on specific commands use \h COMMAND NAME e.g. \h CREATE DATABASE to see how to use the CREATE DATABASE command. For more details on a command read the manual, e.g. the manual on CREATE DATABASE.
Here's the PostgreSQL tutorial, which covers getting started.