why is this showing up? - jupyter

---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-b7eb239f86a7> in <module>
1 # Initialize path to SQLite database
2 path = 'data/classic_rock.db'
----> 3 con = sq3.Connection(path)
4
5
NameError: name 'sq3' is not defined

It looks like from the traceback that you are attempting to use sq3 and you either did not import the library or did not correctly alias the library in question. Cannot know for sure without your code though.

'sq3' is not defined
That's why. Somewhere in your code you're expecting a variable called sql3 but it doesn't exist.

Related

How to get Metadata in python ONVIF?

Currently, I'm looking for metadata access functions using the in Python-onvif.
I want to get the coordinates of "BoundingBox" inside the red box.
How to i access data?
https://www.onvif.org/ver20/analytics/wsdl/analytics.wsdl#op.GetSupportedMetadata
This function was used, but an AttributeError occurred.
from onvif import ONVIFCamera
cam = ONVIFCamera('192.168.100.133', 80, 'ID', 'P/W')
cam.create_analytics_service()
meta = cam.analytics.GetSupportedMetadata()
print(meta)
result:
Traceback (most recent call last):
File "C:\Users\User\anaconda3\envs\py310\lib\site-packages\zeep\proxy.py", line 97, in __getitem__
return self._operations[key]
KeyError: 'GetSupportedMetadata'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\User\AppData\Roaming\JetBrains\PyCharmCE2021.2\scratches\meta_data.py", line 24, in <module>
meta = cam.analytics.GetSupportedMetadata()
File "C:\Users\User\anaconda3\envs\py310\lib\site-packages\onvif\client.py", line 167, in __getattr__
return self.service_wrapper(getattr(self.ws_client, name))
File "C:\Users\User\anaconda3\envs\py310\lib\site-packages\zeep\proxy.py", line 88, in __getattr__
return self[key]
File "C:\Users\User\anaconda3\envs\py310\lib\site-packages\zeep\proxy.py", line 99, in __getitem__
raise AttributeError("Service has no operation %r" % key)
AttributeError: Service has no operation 'GetSupportedMetadata'
I need your help.
I'm not exactly using the same onvif package you are, and I'm not so sure myself how to achieve this, but this is what I've got so far:
Both the package python-onvif, that you are using, and the Valkka inspired implementation I'm using, rely on a folder WSDL which contains pretty old versions of Onvif operations. It seems we both were using version 2.2 while the current version is 20.12.
So what I did was to download the newer versions at their repository and replace the contents of the WSDL folder with the content of the new WSDL folder.
I also had to replace how the paths were built since now there is some folder hierarchy inplace to reach the WSDL files, but after that I was able to call GetSupportedMetadata successfully.

__import__() works with python3.6.5 but does not work with python3.7.3

The following script works fine with python3.6.5 but failed with python3.7.3 in windows 10 (home edition):
mod = __import__(pth, globals(), locals(), ['*'])
With python3.6.5 and python3.7.3, pth, globals() and locals() are almost same as follows (mPayment.py locates in scripts/demo):
pth ==> "scripts.demo.mPayment"
locals() ==> {'pth': 'scripts.demo.mPayment', 'self': <bop.bopModule.MasterModule object at 0x000002586EC3EC88>}
globals() ==> {...} #globals() has nothing to do with "scripts.demo.mPayment"
But with python3.7.3, I got exception:
Exception occurs in importing module demo.mPayment.
Traceback (most recent call last):
File "c:\xxx\b\Module.py", line 50, in _init
mod = __import__(pth, globals(), locals(), ['*'])
ModuleNotFoundError: No module named 'scripts.demo'
Anyone knows what is going on with the __import__() script in python 3.7.3 since it works with python3.6.5. Thanks a lot for your help.
ouyang
I just move the project root path in sys.path to the first one, then __import__() can find those modules.

Changing directory with os in python

I'm trying to change the directory to the folder that contains the folder I'm in.
That is, I'm in /Users/ethanfuerst/Documents/Coding/mpgdata and I'm trying to go back to /Users/ethanfuerst/Documents/Coding and access a text file in the Coding folder.
When I run this code:
import os
print(os.getcwd())
os.chdir('⁨Users/ethanfuerst/Documents/Coding')
I get this output and error
/Users/ethanfuerst/Documents/Coding/mpgdata
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-19-6c6ee01785f6> in <module>
1 import os
2 print(os.getcwd())
----> 3 os.chdir('⁨Users/ethanfuerst/Documents/Coding')
FileNotFoundError: [Errno 2] No such file or directory: '\u2068Users/ethanfuerst/Documents/Coding'
Does anyone know why this could be the case?
Edit: forgot to mention I am on a Mac
Try using C:\ in front of Users. If that does not work, try using .. in the directory specification to go back one directory.
Use double quotes os.chdir("⁨Users/ethanfuerst/Documents/Coding") instead of os.chdir('⁨Users/ethanfuerst/Documents/Coding')

How to add custom JDBC dialects in PySpark

I have a custom JDBC Dialect in Scala, which works flawlessly through registerDialect method in Scala Spark API. I was hoping to use the same class in PySpark by accessing it through
sc._jvm.org.apache.spark.sql.jdbc.JdbcDialects.registerDialect(sc._jvm.com.me.MyJDBCDialect)
But I receive this error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/spark/python/lib/py4j-0.10.4-src.zip/py4j/java_gateway.py", line 1124, in __call__
File "/usr/local/spark/python/lib/py4j-0.10.4-src.zip/py4j/java_gateway.py", line 1094, in _build_args
File "/usr/local/spark/python/lib/py4j-0.10.4-src.zip/py4j/protocol.py", line 289, in get_command_part
File "/usr/local/spark/python/lib/py4j-0.10.4-src.zip/py4j/java_gateway.py", line 1363, in __getattr__
py4j.protocol.Py4JError: com.me.MyJDBCDialect._get_object_id does not exist in the JVM
I'm totally unfamiliar with Py4J but it sounds like _get_object_id error is raised since sc._jvm.com.me.MyJDBCDialect is a Python object and I try to pass it to sc._jvm.org.apache.spark.sql.jdbc.JdbcDialects.registerDialect, which is a Java(?) construct. How do I get around this problem?
This worked for me:
Make sure that your dialect is declared as class, not object
from py4j.java_gateway import java_import
gw = spark.sparkContext._gateway
java_import(gw.jvm, "com.me.MyJDBCDialect")
gw.jvm.org.apache.spark.sql.jdbc.JdbcDialects.registerDialect(
gw.jvm.com.me.MyJDBCDialect())
Note the () - it will call class constructor for your dialect

Updating rows of a column with list of values in PostgreSQL by psychopg2

I have a table environment with a column noise, I need to update all rows in the noise column, with a list of values, new_dB_values_list with len(new_dB_values_list) = no. of rows.
My code is this:
PsqlCon = psycopg2.connect(host="xx.xxx.xxx.xx", dbname='all_green', user='xxxx' , password='yzzxxx')
con = PsqlCon.cursor()
con.execute("""UPDATE environment SET noise new_dB_values_list;""")
What am I doing wrong, what is the correct method. Thanks.
Getting error:
ERROR:root:Internal Python error in the inspect module.
Below is the traceback from this internal error.
Traceback (most recent call last):
psycopg2.ProgrammingError: syntax error at or near "new_dB_values_list"
LINE 1: UPDATE environment SET noise new_dB_values_list;
^
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
AttributeError: 'ProgrammingError' object has no attribute '_render_traceback_'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
AssertionError