Basically I can use ZODB fine. However the ZEO tutorials are all very confusing.
From my understanding you start a server by going into my directory and punchign into the command prompt
python runzeo.py -C zeo.config
Where my zeo.config file is as follows
<zeo>
address localhost:8090
</zeo>
<filestorage>
path C:\\Anaconda\\Lib\\site-packages\\ZEO\\var\\tmp\\Data.fs
</filestorage>
<eventlog>
<logfile>
path C:\\Anaconda\\Lib\\site-packages\\ZEO\\var\\tmp\\zeo.log
format %(asctime)s %(message)s
</logfile>
</eventlog>
When I run it the log file is filled with
2014-07-02T14:49:15 (1948) opening storage '1' using FileStorage
2014-07-02T14:49:15 StorageServer created RW with storages: 1:RW:C:\\Anaconda\\Lib\\site-packages\\ZEO\\var\\tmp\\Data.fs
2014-07-02T14:49:15 (1948) listening on ('localhost', 8090)
Now when I try to get a client to add some random stuff to the database with prints after every line to see how its going:
from ZEO.ClientStorage import ClientStorage
from ZODB import DB
import transaction
print "starting"
storage=ClientStorage(('localhost',8090))
print "storage opened"
db=DB(storage)
conn=db.open()
print "connection opened"
root=conn.root()
print "established connection"
root['letters']=['a','b','c']
print "added values"
transaction.commit()
print "transaction done"
root.close()
print "closed"
My code only prints "starting", no error messages are thrown, so Im assuming that its getting stuck on the storage = ClientStorange(('localhost',8090)) line, my Data.fs file remains unchanged. I have no idea what is wrong and I have consulted all the tutorials.
I'm on Windows using Python 2.7 and installed ZEO / ZODB from pip so I assume they are all up to date versions is that helps.
Any help or pointers to different object orientated databases (with multiple proccess access) would be appreciated.
Thanks everyone
Found the answer to my own question. Seems there is a bug with the implementation of using the localhost in windows. (Running server and client on same machine)
The source code needs an edit:
I have the same problem (can't connect to ZEO Server) using ZODB/ZEO 4.0 with Python 2.7.6 on Windows.
The proposed solution (changing line 446 of ZEO/zrpc/client.py) works for me, so why not incorporate the patch into the 4.0 release too?
- socket.getaddrinfo(host or 'localhost', port)
+ socket.getaddrinfo(host or 'localhost', port, 0, socket.SOCK_STREAM)"
From https://bugs.launchpad.net/zodb/+bug/1004513
Related
I have huge problem with OPCDA and OpenOPC. I should (must) read a set of tags from a remote server, I have no access to the machine in any way. I only know the IP and the OPC server name.
Testing OpenOPC locally with this code all work fine. Otherwise, changing the hostname with the remote one nothing work with 0x800706BA error.
import OpenOPC
import time
try:
opc = OpenOPC.client()
opc.servers()
#change localhost to remote
opc.connect('Matrikon.OPC.Simulation.1', 'localhost')
srvList = opc.list()
print(srvList)
tags = opc.read(opc.list('Simulation Items.Random.Int*'), group='myTest')
for name, value, quality, tagTime in opc.read(opc.list('Simulation Items.Random.Int*'), group='myTest'):
print(name, value, quality, tagTime)
for tag in tags:
print(tag)
except Exception as e:
print('OPC failed')
print(str(e))
pass
finally:
print('END')
Anyone have any ideas on this?
Not having access to the server (set with anonymous logon), I have done DCOM configurations as much as possible.
Does anyone know a procedure for a possible solution?
Thanks!
When I run this script I receive SSH connection failed: Host key is not trusted error, but even connect to this host to take the key, keep to receive this error.
import asyncio, asyncssh, sys
async def run_client():
async with asyncssh.connect('172.18.17.9', username="user", password="admin", port=9321) as conn:
result = await conn.run('display version', check=True)
print(result.stdout, end='')
try:
asyncio.get_event_loop().run_until_complete(run_client())
except (OSError, asyncssh.Error) as exc:
sys.exit('SSH connection failed: ' + str(exc))
Try adding the known_hosts=None parameter to the connect method.
asyncssh.connect('172.18.17.9', username="user", password="admin", port=9321, known_hosts=None)
From asyncssh documentation here:
https://asyncssh.readthedocs.io/en/latest/api.html#asyncssh.SSHClientConnectionOptions
known_hosts (see Specifying known hosts) – (optional) The list of keys
which will be used to validate the server host key presented during
the SSH handshake. If this is not specified, the keys will be looked
up in the file .ssh/known_hosts. If this is explicitly set to None,
server host key validation will be disabled.
With me, it runs smoothly after inserting known_hosts=None
Here's my example when trying the coding sample in Ortega book:
I tried with hostname=ip/username/password of localCentOS, command test is ifconfig
import asyncssh
import asyncio
import getpass
async def execute_command(hostname, command, username, password):
async with asyncssh.connect(hostname, username = username,password=password,known_hosts=None) as connection:
result = await connection.run(command)
return result.stdout
You should always validate the server's public key.
Depending on your use case you can:
Get the servers host keys, bundle them with your app and explicitly pass them to asyncssh (e.g., as string with a path to your known_hosts file).
Manually connect to the server on the command line. SSH will then ask you if you want to trust the server. The keys are then added to ~/.ssh/known_hosts and AsyncSSH will use them.
This is related but maybe not totally your salvation:
https://github.com/ronf/asyncssh/issues/132
The real question you should be asking yourself as you ask this question (help us help you) is where is it all failing? Known-hosts via analogy is like env vars that don't show up when you need them to.
EDIT: Questions that immediately fire. Host key is found but not trusted? Hmm?
EDIT2: Not trying to be harsh towards you but I think it's a helpful corrective. You've got a software library that can find the key but is not known. You're going to come across a lot of scenarios with SSH / shell / env var stuff where things you take for granted aren't known. Think clearly to help yourself and to ask the question better.
I'm making a chat server on Django and atm trying to implement websockets.
It works fine locally but whenever I launch it on Heroku, websocket is unreachable.
Here's my client script:
var loc = window.location
var ws_start = 'ws://'
if (loc.protocol == 'https:'){
ws_start = 'wss://'
}
var endpoint = ws_start + loc.host + loc.pathname
var socket = new WebSocket(endpoint)
Full error code:
WebSocket connection to 'wss://my-app.herokuapp.com/chat' failed: Error during WebSocket handshake: Unexpected response code: 500
I've seen a variety of similar questions already, and they are either left unanswered or delve into dealing with SSL certificate. There's one answer that would potentially save me (and other folks) alot of frustration if anyone was to confirm it's true. It's quite old and there's no feedback after it was posted: https://stackoverflow.com/a/45173822/7446564.
Thanks to Heroku logs, I was able to get the actual error message:
Django daphne asgi: Django can only handle ASGI/HTTP connections, not websocket
This answer helped me fix it: https://stackoverflow.com/a/59909118/7446564
So in conclusion: if you have an error launching websockets on Django, make sure your .asgi file is properly set up. I'll also attach my Procfile below since setting it up first time was also a little journey and I hope it might be helpful as well:
web: daphne my-app.asgi:application --port $PORT --bind 0.0.0.0 -v2
mongodb_uri = "mongodb://[username:password#]XX.XX.XX.XX"
client = MongoClient(mongodb_uri)
db = client['database']
print(db)
collection_taxonomy = db['collection']
doc = collection_taxonomy.find()
pprint.pprint(doc)
for each_doc in doc:
pprint.pprint(each_doc)
I am getting time out error as I try to print each document of the collection. However, I do not get time out error when I try to connect to localhost.
Tried connecting with connect=False
client = MongoClient(mongodb_uri,connect=False)
Still I get time out error while i print each document.
What could be wrong? Appreciate if someone can help me .
I am using Python 3.5 and Pymongo 3.5.1
Thanks,
-Roopa
is "mongodb://[username:password#]XX.XX.XX.XX" the actual value of mongodb_uri or have you substituted that for the value in your actual application?
The "getaddrinfo failed" message indicates that the hostname you put in mongodb_uri is invalid.
Removed square brackets([]) after substituting values in actual application.
"mongodb://username:password#XX.XX.XX.XX"
Works like a charm.!
Thanks a ton.
Roopa
I got the same error when i had a restricted rights on the user account which was trying to connect, so please try changing the user access rights or use a different account with higher privileges
user with the below rights failed
readWrite#dbname.colname
user with the below rights worked (note this is the user created for Atlas application)
atlasAdmin#admin
The URI should be like "mongodb://username:password#host", where the host is the hostname or IP.
This happened to me when I was connecting with the name, but the host name changed, so I changed the URI to connect via the machine's IP.
I am trying to use the Docker Python API to login to a Docker cloud:
https://docker-py.readthedocs.io/en/stable/client.html#creating-a-client1
What is the URL? What is the Port?
I have tried to get it to work with cloud.docker.com, but I am fine with any registry server, so long as it is free to use and I can use it to upload Docker images from one computer and run them on another.
I have already got everything running using my own locally hosted registry, but I can’t seem to figure out how to connect to a server. It’s kind of ridiculous that hosting my own registry is easier than using an existing registry server.
My code looks like this, but I am unsure what the args.* parameters should be:
client = docker.DockerClient(base_url=args.docker_registry)
client.login(username=args.docker_user, password=args.docker_password)
I’m not sure what the base_url needs to be so that I can log in, and the error messages are not helpful at all.
Can you give me an example that works?
The base_url parameter is the URL of the Docker server, not the Docker Registry.
Try something like:
from docker.errors import APIError, TLSParameterError
try:
client = docker.from_env()
client.login(username=args.docker_user, password=args.docker_password, registry=args.docker_registry)
except (APIError, TLSParameterError) as err:
# ...
Here's how I have logged in to Docker using Python:
import docker
client = docker.from_env()
client.login(username='USERNAME', password='PASSWORD', email='EMAIL',
registry='https://index.docker.io/v1/')
and here's what it returns:
{'IdentityToken': '', 'Status': 'Login Succeeded'}
So, that means it has been logged in successfully.
I still haven't figured out what the registry of cloud.docker.com is called, but I got it to work by switching to quay.io as my registry server, which works with the intuitive registry='quay.io'