Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #102836
| Path | csiph.com!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Unable to insert data into MongoDB. |
| Date | Thu, 11 Feb 2016 20:06:44 -0500 |
| Organization | IISS Elusive Unicorn |
| Lines | 79 |
| Message-ID | <mailman.62.1455239211.22075.python-list@python.org> (permalink) |
| References | <eebb44e3-fcd3-4503-ad2b-5cfcc75ef6fa@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de xF5XpTFUaFJaEiG3qj4xUAb475JE6ny4BarH6FIYxtyA== |
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'data:': 0.07; 'socket': 0.07; 'addr': 0.09; 'message-id:@4ax.com': 0.09; 'port))': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:into': 0.09; 'thu,': 0.15; '"127.0.0.1"': 0.16; "'connection": 0.16; '1024': 0.16; '2016': 0.16; '>try:': 0.16; 'conn.close()': 0.16; 'hard-code': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 's.accept()': 0.16; 'skip:> 20': 0.16; 'there?': 0.16; 'true:': 0.16; 'url:home': 0.18; 'all,': 0.20; 'trying': 0.22; 'defined': 0.23; 'feb': 0.23; 'previously': 0.24; "doesn't": 0.26; 'header:X -Complaints-To:1': 0.26; 'data,': 0.27; 'invoke': 0.29; "i'm": 0.30; 'connection': 0.30; 'skip:d 20': 0.34; 'server': 0.34; 'attempt': 0.35; 'skip:> 10': 0.35; "isn't": 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'client': 0.37; 'received:org': 0.37; 'charset:us-ascii': 0.37; 'why': 0.39; 'data': 0.39; "didn't": 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'waiting': 0.60; 'close': 0.61; 'above,': 0.63; 'binding': 0.66; 'here': 0.66; 'receive': 0.71; 'yourself': 0.73; 'plc': 0.76; 'abc': 0.91; 'dennis': 0.91; 'received:108': 0.93; 'tied': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | adsl-108-79-217-78.dsl.klmzmi.sbcglobal.net |
| X-Newsreader | Forte Agent 6.00/32.1186 |
| X-No-Archive | YES |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21rc2 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:102836 |
Show key headers only | View raw
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