Looking for other similar errors, we have an issue on loading the DLL library supplied with the Yenista laser instrument.
The DLL is correctly loaded while using the python version indicated in the instrument guide (Python 3.4).
Unfortunately, we need Python 3.10 or at least (>3.8) for other instruments.
We have two different files in our folder: CT400_lib.dll and CT400_lib.h (header file).
It looks like that, using this Python version, the DLL functions cause the following error: OSError: exception: access violation reading 0xFFFFFFFFB6E38700
According to the documentation of ctype, it seems that the DLL is resolved differently in the two Python versions.
We have no idea how to use this DLL with the newer Python version. The instrument is old and the company that produces this instrument does not exists anymore.
Our code:
from ctypes import *
dll_ct400 = cdll.LoadLibrary(r"address")
# (we also tried with "dll_ct400 =WinDLL(r"address"))
class Yenista_Control():
[...]
def initYenista(self):
tcError = create_string_buffer(1024)
strRet = create_string_buffer(1024)
iErrorSize = c_int * 1
(iError) = (iErrorSize())
self.uiHandle = c_longlong(dll_ct400.CT400_Init(byref(iError)))
print("{}{}".format("Error/Warning: ", iError[0]))
if self.uiHandle:
strRet = 'OK'
else: strRet = 'Error: could not connect to CT400'
print(strRet)
return strRet
def YenistaLaserSetting(self):
dll_ct400.CT400_SetLaser(self.uiHandle, self.LI_1, self.ENABLE, 10, self.LS_TunicsT100s_HP,
c_double(1530.0), c_double(1570.0), 100)
if self.uiHandle:
strRet = 'OK'
else: strRet = 'Error: could not connect to CT400'
print(strRet)
return strRet
It seems recognizing the "dll_ct400.CT400_Init" in def initYenista, giving the error when trying to access all other functions, as the YenistaLaserSetting reported above.
Related
We have a python library(Lets call it TestLibrary), made as a 'whl' file.
We are consuming that library in another python project(Main Project)(flask based).
In test library, we are calling a dll(C#, Net standard 2.0) , which has few encryption methods, which returns us encrypted data.
Now this test library gives error when called those encryption methods from TestLibrary.
How can we consume those dll's in TestLibrary, and get the data on main project.
// below code is in TestLibrary
def get_encrypted_data():
try:
clr.AddReference('folder/dlls/EncryptionDLL')
from EncryptionDLL import EncryptionClass
encryptionObj = EncryptionClass()
encryptedData = encryptionObj.Encrypt('Data', 'Encryption Key')
return encryptedData
except Exception as e:
return e
//Below Code is in Flask Application
//pip install TestLibrary
from TestLibrary import get_encrypted_data
encryptedData = get_encrypted_data(); //Error here, not able to read dll
I have tried it with, PythonNet, LibMono installation. It works fine when created a POC with only that dll in python.
When we place it another library and consume that library, we are getting error.
When I'm trying to read data from sqlalchemy df=pd.read_sql_table(table, con, schema) getting runtime error :
runtime/cgo: could not obtain pthread_keys
tried 0x115 0x116 0x117 0x118 0x119 0x11a 0x11b 0x11c 0x11d 0x11e 0x11f 0x120 0x121 0x122 0x123 0x124 0x125 0x126 0x127 0x128 0x129 0x12a 0x12b 0x12c 0x12d 0x12e 0x12f 0x130 0x131 0x132 0x133 0x134 0x135 0x136 0x137 0x138 0x139 0x13a 0x13b 0x13c 0x13d 0x13e 0x13f 0x140 0x141 0x142 0x143 0x144 0x145 0x146 0x147 0x148 0x149 0x14a 0x14b 0x14c 0x14d 0x14e 0x14f 0x150 0x151 0x152 0x153 0x154 0x155 0x156 0x157 0x158 0x159 0x15a 0x15b 0x15c 0x15d 0x15e 0x15f 0x160 0x161 0x162 0x163 0x164 0x165 0x166 0x167 0x168 0x169 0x16a 0x16b 0x16c 0x16d 0x16e 0x16f 0x170 0x171 0x172 0x173 0x174 0x175 0x176 0x177 0x178 0x179 0x17a 0x17b 0x17c 0x17d 0x17e 0x17f 0x180 0x181 0x182 0x183 0x184 0x185 0x186 0x187 0x188 0x189 0x18a 0x18b 0x18c 0x18d 0x18e 0x18f 0x190 0x191 0x192 0x193 0x194
Below is the code:
class TeradataWriter:
def __init__(self):
print("in init")
def read_data_from_teradata(self):
try:
print('Create main')
import pdb;pdb.set_trace()
eng = self.create_connection_engine()
df = pd.read_sql_table("table_name", eng, schema="schema")
print(df)
except Exception as ex:
print('Exception: %s', ex.with_traceback())
def create_connection_engine(self):
try:
return create_engine('teradatasql://' + constants.TERADATA_HOST + '/?user='+ constants.TERADATA_USER_NAME + '&password=' + constants.TERADATA_PWD, echo=False)
except Exception as ex:
LOGGER.error('Exception: %s', ex)
raise Exception(message_constants.ERROR_WHILE_CREATING_CONNECTION_WITH_TERADATA)
if __name__ == "__main__":
p = TeradataWriter()
p.write_dataframe_to_teradata()
Edit: This is fixed. I was finally able to get their support and engineering team to reproduce the issue. They now build the driver with a newer version of go. Upgrade to >= 17.0.3, and you shouldn't see anymore segfaults.
I think I finally figured out why this happens. According to this Go issue, it happens if "If the host process spawns threads prior to loading the shared library, the offset will have changed."
In my case, I was importing matplotlib.pyplot in IPython before calling code that loads the shared library. This starts an event loop and causes the conditions that lead to the segfault.
I changed my code to import matplotlib.pyplot after configuring the teradata driver, and it went away.
According to the Go issue, they just need to recompile the library with a newer version of Go, which I've asked them to do. We'll see what they say.
I have run in to same issue -
So to fix the problem, I moved connect statement to main and it kind of fixed. Its worth trying in your case.
I'm working on a project where I have to control 8 audio channel.
I'm programming in python3 using alsaaudio library. It all worked but I have these 3 errors and, once I start the program, my internet connection goes down.
In the following code, you can see how I initialize the device (octosound card by AudioInjector). Please note that if the indentitation is wrong is just because a copy paste error.
import alsaaudio
def start_device(ch):
variables.mut.acquire()
if variables.device_flag[ch] == 1:
try:
variables.device_PCM[ch] = alsaaudio.PCM(type=alsaaudio.PCM_PLAYBACK, mode = alsaaudio.PCM_NORMAL,device=variables.device_name[ch])
variables.device_flag[ch] = 0 # device open
print('device -%s- OPEN' % (variables.device_name[ch]))
except:
print("Except raised")
json_builder.jsonerror("Init device ch" + str(ch) +" FAILED to OPEN",ch)
variables.device_flag[ch] == 1
else:
print("Device -%s- already opened" % (variables.device_name[ch]))
variables.mut.release()
The strange things are that this code works and I can drive all 8 channels but I got 3 errors and my internet stop working:
message: "Module 'alsaaudio' has no 'PCM' member"
message: "Module 'alsaaudio' has no 'PCM_PLAYBACK' member"
message: "Module 'alsaaudio' has no 'PCM_NORMAL' member"
(the device=device_name[ch] works, no error)
Well, I will recommend you to use Alvas.Audio Library which can edit, convert, play, pause convert audio files. The C# Alvas.Audio library can also be used to convert headerless format (SLINEAR) etc.
http://alvas.net/alvas.audio,tips.aspx
Moreover it helps to extract AVI streams and convert one file format to another. So, try the Alvas.Audio C# library and get free trial https://www.filerepairtools.com/alavas-audio-library.html
import scapy.all as scapy
import requests
import json
This code work with API for getting information about venders
def vender_finding(mac_adr):
mac_url = 'http://macvendors.co/api/%s'
vender = (requests.get(mac_url % mac_adr))
response_dict = json.loads(json.dumps(vender.json()))
return response_dict['result']['company']
This code returns all devices connected to the network. result is something like this
the result of this code
def scan(ip):
arp_request = scapy.ARP(pdst=ip)
broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
arp_request_broadcast = broadcast/arp_request
This is the line which gives an error
answered_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]
clents_list = []
for element in answered_list[1:]:
company = vender_finding(element[1].hwsrc)
clent_dict = {"ip": element[1].psrc, "mac": element[1].hwsrc, "vender": company}
clents_list.append(clent_dict)
print(clents_list)
return clents_list
scan('192.168.1.0/24')
but now its return error like this.
In here now a new error starts to occur.
answered_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]
This the error that I am getting.
raise ValueError("Unknown network interface %r" % name)
ValueError: Unknown network interface None
By installing the following software issue solved.
1.python 2.7.2 from python.org
2.Microsoft Visual C++ Compiler for Python 2.7 from https://www.microsoft.com/en-us/download/confirmation.aspx?id=44266.
(check this link for more. Microsoft Visual C++ 9.0 is required)
3.pip install scapy==2.4.3rc1 (this is recommended by StackOverflow contributor. this work very well.)
(check these link answer for a recommendation by user Cukic0d. GUID number of windows interface giving error: ValueError: Unknown network interface '{1619EEF1-4D71-4831-87AC-8E5DC3AA516A}')
4.winpcap (to perform scapy sniff() must install this)
Install python 2.7.2 and then install Microsoft Visual C++ Compiler for Python 2.7
You can try "iface" with your network interface.
Ex:
sendp(Ether()/IP(dst="1.2.3.4",ttl=(1,4)), iface="eth1")
More info: https://scapy.readthedocs.io/en/latest/usage.html
using pycharm (python 3) to write a python program,there are part of the program:
class GraphAPI(object):
...
def get_version(self):
'''Fetch the current version number of the Graph API being used'''
args = {"access_token":self.access_token}
try:
response = self.request(
"GET",
FACEBOOK_GRAPH_URL + self.version + "/me",
params = args,
timeout = self.timeout,
proxies = self.proxies
)
except requests.HTTPError as e:
response = json.loads(e.read())
raise GraphAPIError(response)
However, the "e.read()" is in yellow color, when moving mouse on it, it shows:
Unresolved attribute reference 'read' for class 'HTTPError',This inspection
detected names that should resolve but don't. Due to dynamic dispatch and
duck typing, this is possible in a limited but useful number of cases.Top-
level and class-level items are supported better than instance items
pycharm tells you that it doesn't understand that this "e" of type requests.HTTPError does have a read() method.
So, most likely, you are simply missing the correct import statement. You have to make sure that the "name" requests.HTTPError is known to your IDE.
(and just for the record: pycharm is usually correct about such assignments, so when pycharm gives you an error for that line, your code has in fact a problem and will fail at runtime)