Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #102836
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Unable to insert data into MongoDB. |
| Date | 2016-02-11 20:06 -0500 |
| Organization | IISS Elusive Unicorn |
| Message-ID | <mailman.62.1455239211.22075.python-list@python.org> (permalink) |
| References | <eebb44e3-fcd3-4503-ad2b-5cfcc75ef6fa@googlegroups.com> |
On Thu, 11 Feb 2016 07:12:06 -0800 (PST), Arjun Srivatsa
<arjuns123@gmail.com> declaimed the following:
>
># Connection to server (PLC) on port 27017
>server = socket.socket()
>host = "10.52.124.135" #IP of PLC
>port = 27017
>BUFFER_SIZE = 1024
>###############
>
>server.connect((host, port))
>print server.recv(1024)
>
>server.close
>
>#Connection to Client (Mongodb) on port 27017
>IP = "127.0.0.1"
>PORT = 27017
>BUFFER_SIZE = 1024
>
>client = MongoClient('127.0.0.1', 27017)
Why hard-code the address/port when you just previously defined them as
pseudo-constants IP and PORT?
>db = client.test_database
>
>s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>s.bind((IP, PORT))
Why are you now binding a new socket to the same IP/PORT used by the
database object? Doesn't the "client" object already have a binding to the
database? Don't you then use methods of "client" and "db" to work with data
there?
>s.listen(1)
>
Isn't this waiting for some outside process to attempt to connect to
the same IP/PORT that you used to connect to the database?
>#connections loop
>while True:
>conn, addr = s.accept()
>print 'Connection address:',addr
>try:
># read loop
> while True:
> data = server.recv(BUFFER_SIZE)
Now I'm really confused -- you (failed -- since you didn't () invoke
it) to close the "server" connection above, but here you are trying to
receive data from it.
>
> if not data: break
> conn.sendall(data)
>
Who connected? After all, you tied yourself to the same IP/PORT as the
database?
>
> # send to MongoDB
>
> mongodoc = { "data": data, "date" : datetime.datetime.utcnow() }
>
>
> ABC = db.ABC
> ABC_id = ABC.insert_one(mongodoc).inserted_id
>
>finally:
> conn.close()
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Unable to insert data into MongoDB. Arjun Srivatsa <arjuns123@gmail.com> - 2016-02-11 07:12 -0800
Re: Unable to insert data into MongoDB. Arjun Srivatsa <arjuns123@gmail.com> - 2016-02-11 08:07 -0800
Re: Unable to insert data into MongoDB. MRAB <python@mrabarnett.plus.com> - 2016-02-11 16:09 +0000
Re: Unable to insert data into MongoDB. Arjun Srivatsa <arjuns123@gmail.com> - 2016-02-15 02:44 -0800
Re: Unable to insert data into MongoDB. Peter Otten <__peter__@web.de> - 2016-02-15 12:36 +0100
Re: Unable to insert data into MongoDB. Arjun Srivatsa <arjuns123@gmail.com> - 2016-02-15 07:00 -0800
Re: Unable to insert data into MongoDB. Arjun Srivatsa <arjuns123@gmail.com> - 2016-02-15 07:28 -0800
Re: Unable to insert data into MongoDB. Peter Otten <__peter__@web.de> - 2016-02-15 17:33 +0100
Re: Unable to insert data into MongoDB. Arjun Srivatsa <arjuns123@gmail.com> - 2016-02-16 04:41 -0800
Re: Unable to insert data into MongoDB. Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-02-11 20:06 -0500
csiph-web