Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #102812
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2016-02-11 08:07 -0800 |
| References | <eebb44e3-fcd3-4503-ad2b-5cfcc75ef6fa@googlegroups.com> |
| Message-ID | <8265726c-a5af-4110-8dcd-33dccd5aecb3@googlegroups.com> (permalink) |
| Subject | Re: Unable to insert data into MongoDB. |
| From | Arjun Srivatsa <arjuns123@gmail.com> |
Hello,
I changed
PORT = 27017
to
PORT = 55555.
I am not getting the error anymore. But I am still unable to insert the data into MongoDB.
On Thursday, February 11, 2016 at 4:12:30 PM UTC+1, Arjun Srivatsa wrote:
> Hi guys. I am basically transferring the data from PLC to PC (where the Python API runs) but I'm unable to insert into MongoDB thereafter. When I run the Python script on IDLE, the output is
>
> Hello World!
> Traceback (most recent call last): File "C:\Users\SRA2LO\Desktop\API.py", line 32, in <module> s.bind((IP, PORT)) File "C:\Python27\lib\socket.py", line 228, in meth return getattr(self._sock,name)(*args) error: [Errno 10013] An attempt was made to access a socket in a way forbidden by its access permissions
> and when I change the IP of MongoDB server, it shows
>
>
> Hello World!
> Traceback (most recent call last): File "C:\Users\SRA2LO\Desktop\API.py", line 32, in <module> s.bind((IP, PORT)) File "C:\Python27\lib\socket.py", line 228, in meth return getattr(self._sock,name)(*args) error: [Errno 10049] The requested address is not valid in its context.
>
> Could you please help me out? I have disabled the firewall as well.
>
> Here's the API I have written.
>
> #!/usr/bin/python
>
> import socket
> import socket
> from pymongo import MongoClient
> #from eve import Eve
> import datetime
>
> # 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)
> db = client.test_database
>
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> s.bind((IP, PORT))
> s.listen(1)
>
> #connections loop
> while True:
> conn, addr = s.accept()
> print 'Connection address:',addr
> try:
> # read loop
> while True:
> data = server.recv(BUFFER_SIZE)
>
> if not data: break
> conn.sendall(data)
>
>
> # send to MongoDB
>
> mongodoc = { "data": data, "date" : datetime.datetime.utcnow() }
>
>
> ABC = db.ABC
> ABC_id = ABC.insert_one(mongodoc).inserted_id
>
> finally:
> conn.close()
Back to comp.lang.python | Previous | Next — Previous in thread | Next 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