Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102813

Re: Unable to insert data into MongoDB.

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From MRAB <python@mrabarnett.plus.com>
Newsgroups comp.lang.python
Subject Re: Unable to insert data into MongoDB.
Date Thu, 11 Feb 2016 16:09:29 +0000
Lines 77
Message-ID <mailman.50.1455206980.22075.python-list@python.org> (permalink)
References <eebb44e3-fcd3-4503-ad2b-5cfcc75ef6fa@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de 8ytOtOVcGMwWkFMlKVlr0QmM3UtZN2FwJDCxrsCsqRSQ==
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'error:': 0.05; 'finally:': 0.05; 'data:': 0.07; 'permissions': 0.07; 'socket': 0.07; 'api': 0.09; 'addr': 0.09; 'guys.': 0.09; 'port))': 0.09; 'subject:into': 0.09; 'python': 0.10; 'output': 0.13; 'server,': 0.15; '"127.0.0.1"': 0.16; '"while': 0.16; "'connection": 0.16; '1024': 0.16; '32,': 0.16; 'conn,': 0.16; 'conn.close()': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'idle,': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'out?': 0.16; 'received:192.168.1.4': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'relevant,': 0.16; 's.accept()': 0.16; 'socket.': 0.16; 'true:': 0.16; 'written.': 0.16; 'wrote:': 0.16; 'basically': 0.18; 'try:': 0.18; 'skip:" 30': 0.20; 'posted': 0.21; 'context.': 0.22; 'disabled': 0.22; '(where': 0.23; 'insert': 0.23; 'import': 0.24; '(most': 0.24; 'header:In-Reply- To:1': 0.24; 'script': 0.25; 'header:User-Agent:1': 0.26; 'skip:" 20': 0.26; 'skip:# 10': 0.27; 'data,': 0.27; 'host': 0.28; 'firewall': 0.29; "i'm": 0.30; 'print': 0.30; 'connection': 0.30; 'code': 0.30; 'skip:g 30': 0.30; 'received:84': 0.32; 'run': 0.33; 'traceback': 0.33; 'file': 0.34; 'skip:d 20': 0.34; 'server': 0.34; 'could': 0.35; 'attempt': 0.35; "isn't": 0.35; 'but': 0.36; 'instead': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'client': 0.37; "won't": 0.38; 'data': 0.39; "didn't": 0.39; 'unable': 0.39; 'received:192': 0.39; 'well.': 0.40; 'to:addr:python.org': 0.40; 'close': 0.61; 'address': 0.61; 'plc': 0.76; 'abc': 0.91
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=Iat6Ijea c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=IkcTkHD0fZMA:10 a=eDmjBxMJmTBCv_Io0uIA:9 a=9Gz7Xmp9HVpZZd0m:21 a=cYHlsJoDUoPYQTbW:21 a=QEXdDO2ut3YA:10
X-AUTH mrabarnett@:2500
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1
In-Reply-To <eebb44e3-fcd3-4503-ad2b-5cfcc75ef6fa@googlegroups.com>
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:102813

Show key headers only | View raw


On 2016-02-11 15:12, 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()
>
I don't know whether it's relevant, but you didn't close the server 
socket. You have "server.close" instead of "server.close()".

Also, the code as posted won't compile because the block after the 
"while True:" isn't indented.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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