client=MongoClient() syntax error using pyspark
<p>I'm trying to realize analystics through Spark using Pyspark. The event, once analyzed, should be send in a Mongo database.
The python code is in the file myFile.py
However, when running this command:</p>

<pre><code>spark-2.0.0/bin/spark-submit myFile.py
</code></pre>

<p>I have the following error:</p>

<pre><code>client=MongoClient('localhost' , 27017)
     ^
SyntaxError: invalid syntax
</code></pre>

<p>This being said, I have tried with spaces around the "=" but it did not change a thing, I checked for unwanted spaces before the line or wrong indentation but everything looks fine. Moreover, pymongo is imported at the beginning of the file</p>

<p>I found this configuration online, looking on tutorials and checking in the pymongo documentation.</p>

<p>Can anyone help on this matter?
I apologize for any error in my English, it is not my native language.</p>

<p><strong>Edit:</strong>
Here is the surrounding code:</p>

<pre><code>if "User dn cn" in part2:
   usrDnCnMsg = part2.split(",")
   usrDnCnElements = list()
   for element in usrDnCnMsg:
      usrDnCnElements.append(element.split("=")[1].lstrop().rstrip()
   # sending event to DB
   client=MongoClient('localhost' , 27017)
   db = client.TEST
   found = db.user.findOne({"usrName":usrDnCnElements[0]})
   if found == None:
      result = db.user.insertOne({"usrName":usrDnCnElements[0],"usrGrp":"null"})
      result = db.usrDnCn.insertOne({"timestamp":timestamp,"usrID":db.user.findOne({"usrName":usrDnCnElements[0]})["_id"],"country":usrDnCnElements[1],"ou":usrDnCnElements[2],"dn":usrDnCnElements[3],"dn1":usrDnCnElements[4]})
   # close connection
   client.close()
</code></pre>

<p>This code is itself inside another if.</p>

<p>So I'm answering my own question.</p>

<p>Some typing errors were in my code inducing error messages that were not explicitely designating those typing errors. Also, my pymongo installation was not correctly done.
I corrected the typing errors in my code and reinstalled pymongo and it seems to work now.</p>

python mongodb apache-spark pymongo