How do I set the Engine used by ExecJS to NodeJS? - python

I'm trying to use the following package: https://github.com/Anorov/cloudflare-scrape/blob/master/cfscrape/init.py
I have the following test file:
import cfscrape
import sys
import execjs
who = sys.argv[1]
scraper = cfscrape.create_scraper()
print scraper.get(who).content
Which is outputting the following error:
Traceback (most recent call last): File "test.py", line 1, in import cfscrape File "build/bdist.macosx-10.10-intel/egg/cfscrape/__init__.py", line 17, in EnvironmentError: Your Javascript runtime 'JavaScriptCore' is not supported due to security concerns. Please use Node.js, V8, or PyV8.
Can anyone point me in the right direction to change my JS_ENGINE from JavaScriptCore to NodeJs

Related

Call C# DLL API from python

I got some C# DLL file with methods inside it and I'm trying to use it from python:
import sys
sys.path.append(r"C:\Users\ssandler\Documents\Python_projects\CLR_TEST")
import clr
clr.AddReference(r"C:\Users\ssandler\Documents\Python_projects\CLR_TEST\CAPLIB.DLL")
from CAPLIB import CapLib
cl = CapLib()
cl.CAP_ClearCsrRegister()
but get the folowing error:
Traceback (most recent call last):
File "C:/Users/ssandler/Documents/Python_projects/CLR_TEST/test.py", line 14, in
cl.CAP_ClearCsrRegister()
System.NullReferenceException: Object reference not set to an instance of an object.
at CAPLIB.CapLib.CAP_ClearCsrRegister()
this method exists in that class:
.NET reflector capture
Any ideas?

Importing json2xml library gives invalid syntax error

I am trying to import the following library:
import json2xml
from json2xml.utils import readfromstring
However, when I execute the second line I get this error:
Traceback (most recent call last):
File "C:\Users\denis\Desktop\Pazaruvaj Upload\Pazaruvaj_Part1_Test.py", line 12, in <module>
from json2xml.utils import readfromurl, readfromstring, readfromjson
File "C:\Python27\lib\site-packages\json2xml\utils.py", line 19
def readfromjson(filename: str) -> dict:
^
SyntaxError: invalid syntax
Couldn't find anything online about this issue.
Note I don't write from json2xml import json2xml because it gives the same error
According to https://pypi.org/project/json2xml/, json2xml is not compatible with Python2.
Python2 is deprecated, please update to Python3. Then this library should work.

onnxruntime Package installation in Python Plugin from Azure Data Explorer Fails

I want to install the onnxruntime package using the python plugin from the Azure Data Explorer.
I followed the instructions from this site https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/pythonplugin?pivots=azuredataexplorer.
However, i dont get it to work properly. It always tells me "ImportError: cannot import name 'get_all_providers'"
Here is my kusto statement from the Azure Data Explorer:
let predict_onnx_fl=(samples:(*), model_name:string, features_cols:dynamic, pred_col:string){
let kwargs = pack('features_cols', features_cols, 'pred_col', pred_col);
let code =
'\n'
'import pickle\n'
'import binascii\n'
'from sandbox_utils import Zipackage\n'
'Zipackage.install("onnx2.zip")\n'
'import onnxruntime as rt\n'
'\n'
'smodel = "08031208736b6c326f6e6e781a05312e372e30220761692e6f6e6e78280032003adb040af0010a0b666c6f61745f696e70757412056c6162656c121270726f626162696c6974795f74656e736f721a104c696e656172436c617373696669657222104c696e656172436c61737369666965722a210a13636c6173736c6162656c735f737472696e67734a026e6f4a03796573a001082a250a0c636f656666696369656e74733d637146c13d000000803d637146413d00000000a001062a190a0a696e74657263657074733d391eba433d391ebac3a001062a120a0b6d756c74695f636c6173731801a001022a1d0a0e706f73745f7472616e73666f726d22084c4f474953544943a001033a0a61692e6f6e6e782e6d6c0a560a1270726f626162696c6974795f74656e736f72120d70726f626162696c69746965731a0a4e6f726d616c697a6572220a4e6f726d616c697a65722a0d0a046e6f726d22024c31a001033a0a61692e6f6e6e782e6d6c0a2b0a056c6162656c120c6f75747075745f6c6162656c1a084964656e7469747922084964656e746974793a000a620a0d70726f626162696c697469657312126f75747075745f70726f626162696c6974791a065a69704d617022065a69704d61702a210a13636c6173736c6162656c735f737472696e67734a026e6f4a03796573a001083a0a61692e6f6e6e782e6d6c122039626230386630393965383234353034616662366161653835633236663437355a1b0a0b666c6f61745f696e707574120c0a0a080112060a000a02080262180a0c6f75747075745f6c6162656c12080a06080812020a0062240a126f75747075745f70726f626162696c697479120e220c0a0a2a08080812040a02080142040a001001420e0a0a61692e6f6e6e782e6d6c1001"\n'
'features_cols = kargs["features_cols"]\n'
'pred_col = kargs["pred_col"]\n'
'bmodel = binascii.unhexlify(smodel)\n'
'\n'
'features_cols = kargs["features_cols"]\n'
'pred_col = kargs["pred_col"]\n'
'\n'
'sess = rt.InferenceSession(bmodel)\n'
'input_name = sess.get_inputs()[0].name\n'
'label_name = sess.get_outputs()[0].name\n'
'df1 = df[features_cols]\n'
'predictions = sess.run([label_name], {input_name: df1.values.astype(np.float32)})[0]\n'
'\n'
'result = df\n'
'result[pred_col] = pd.DataFrame(predictions, columns=[pred_col])'
'\n'
;
samples | evaluate python(typeof(*), code, kwargs, external_artifacts=pack('onnx2.zip', 'LINK TO SANDBOX'))
};
RAW_TSM_ReadingValues
| take 1000
| extend pred_Occupancy=bool(0)
| invoke predict_onnx_fl('ONNX', pack_array('value', 'value_tariff'), 'pred_Occupancy')
And here is the Error Statement I get:
Query execution has resulted in error (0x80131500): Partial query failure: 0x80131500 (message:
'Encountered an error during execution of local sandbox. Error details: Python code execution failed
with the following error: ImportError: cannot import name 'get_all_providers'; Traceback (most
recent call last):
File "C:\Enlistments\Kusto\Azure-Kusto-
Service\Src\Common\Kusto.Cloud.Platform.Sandbox\Languages\Python\execute_python.py", line 155, in
exec_python
File "<string>", line 8, in <module>
File "C:\Temp\onnxruntime\__init__.py", line 13, in <module>
from onnxruntime.capi._pybind_state import get_all_providers, get_available_providers, get_device,
set_seed, \
ImportError: cannot import name 'get_all_providers'
. ==> ExecutePluginOperator failure: ', details: 'Source: DataNode
[0]Kusto.Cloud.Platform.Sandbox.Exceptions.SandboxExecutionException: Encountered an error during
execution of local sandbox. Error details: Python code execution failed with the following error:
ImportError: cannot import name 'get_all_providers'; Traceback (most recent call last):
File "C:\Enlistments\Kusto\Azure-Kusto-
Service\Src\Common\Kusto.Cloud.Platform.Sandbox\Languages\Python\execute_python.py", line 155, in
exec_python
File "<string>", line 8, in <module>
File "C:\Temp\onnxruntime\__init__.py", line 13, in <module>
from onnxruntime.capi._pybind_state import get_all_providers, get_available_providers,
get_device, set_seed, \
ImportError: cannot import name 'get_all_providers'
.
Timestamp=2020-09-17T10:31:20.4439778Z
ClientRequestId=KustoWebV2;f7d0f61f-7b8c-4855-a5fa-a5a5370725ba
ActivityId=fdee5c65-0d8f-47b0-bda8-9a26553eaf22
ActivityType=DN.FE.ExecuteQuery
ServiceAlias=DACHSADXCLUSTEREUW
MachineName=KEngine000000
ProcessName=Kusto.WinSvc.Svc
ProcessId=5812
ThreadId=332
AppDomainName=Kusto.WinSvc.Svc.exe
ActivityStack=(Activity stack: CRID=KustoWebV2;f7d0f61f-7b8c-4855-a5fa-a5a525ba ARID=fdee5-0d8f-
47b0-bda8-9a2655af22 > DN.FE.ExecuteQuery/ff6edaa-e90-4050-b5c9-6f7a59abd6)
ErrorCode=
ErrorReason=
ErrorMessage=
DataSource=
DatabaseName=
ClientRequestId=
ActivityId=00000000-0000-0000-0000-000000000000
Details=Python code execution failed with the following error: ImportError: cannot import name
'get_all_providers'; Traceback (most recent call last):
File "C:\Enlistments\Kusto\Azure-Kusto-
Service\Src\Common\Kusto.Cloud.Platform.Sandbox\Languages\Python\execute_python.py", line 155, in
exec_python
File "<string>", line 8, in <module>
File "C:\Temp\onnxruntime\__init__.py", line 13, in <module>
from onnxruntime.capi._pybind_state import get_all_providers, get_available_providers,
get_device, set_seed, \
ImportError: cannot import name 'get_all_providers'
at Kusto.DataNode.QueryService.PluginsV2.SandboxedPluginBase.ExecuteInSandbox(SandboxKind
sandboxKind, ISandboxManager sandboxManager, ClientRequestProperties clientRequestProperties,
IDictionary`2 argumentsPropertyBag, IStreamSource inputStreamSource, IDictionary`2
externalArtifacts, OperationStatistics& operationStatistics) in
C:\source\Src\Engine\DataNode\QueryService\PluginsV2\DistributedPlugins\SandboxedPluginBase.cs:line 56
at
Kusto.DataNode.QueryService.PluginsV2.ScriptExecutionPluginBase.Execute(PluginDistributionCapsule
distributionCapsule, ClientRequestProperties clientRequestProperties, IStreamSource
inputStreamSource, OperationStatistics& operationStatistics) in C:\source\Src\Engine\DataNode\QueryService\PluginsV2\DistributedPlugins\Languages\ScriptExecutionPluginBase.cs:line 144
at Kusto.DataNode.DataEngineQueryPlan.DataEngineQueryProcessor.DataEngineQueryCallback.ExecutePluginOperator(String pluginName, DataSourceStreamFormat inputStreamFormat, DataSourceStreamFormat outputStreamFormat, String pluginSerializedContext, String serializedQueryContextProperties, IStreamSource inputStream, OperationStatistics& operationStatistics) in C:\source\Src\Engine\DataNode\QueryService\DataEngineQueryPlan\DataEngineQueryProcessor.cs:line 455').
clientRequestId: KustoWebV2;f7d0f61f-7bc-4855-a5fa-a5a53ba
If anyone has an idea what the problem could be i would be really grateful!
We decided to add the onnxruntime package to the common image, avoiding issues like the one you faced. This update already started to roll out into production clusters, and is expected to be available in 1-2 weeks (cluster dependent). Once it's deployed you could use it as explained in the new function predict_onnx_fl().
thanks,
Adi

Problem with urllib source code in Eclipse?

I am having a bizarre problem in which Eclipse is raising an error for the source code of a python Lib package. I am using Python 3.7.1.
The relevant line is:
import urllib.request.urlopen as uReq
I don't believe the python interpreter I'm using is relevant to this particular problem. Nevertheless, here is the code for it. (I know, it's probably horrendous. If you know a better way to do this, please kindly point me in the right direction; this is my first time using jython and I'm sure it shows.)
interpreter = new PythonInterpreter();
interpreter.exec("import sys");
interpreter.exec("import os");
interpreter.exec("sys.path.insert(0, os.getcwd() + '\\src\\python')");
interpreter.exec("sys.path.insert(0, os.getcwd() + '\\Lib')");
interpreter.exec("sys.path.insert(0, os.getcwd() + '\\Lib\\site-packages')");
interpreter.exec("print(sys.path[0])");
interpreter.exec("from myscraper import validateUrl");
The error:
Exception in thread "AWT-EventQueue-0" Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\...\ThreadTracker\src\python\myscraper.py", line 6, in <module>
import urllib.request.urlopen as uReq
SyntaxError: ("mismatched input ',' expecting NAME",
('C:\\Users\\...\\ThreadTracker\\Lib\\urllib\\request.py', 140, 13, '
*, cafile=None, capath=None, cadefault=False, context=None):\n'))
Which seems to be having a problem with this line of code from the source file:
def urlopen(url, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
*, cafile=None, capath=None, cadefault=False, context=None):
I saw on another post that urllib3 could be used as well, so I tried:
from urllib3 import request as uReq
But this came up with its own error:
Exception in thread "AWT-EventQueue-0" Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\Christina\ThreadTracker\src\python\myscraper.py", line 6, in <module>
from urllib3 import request as uReq
File "C:\Users\Christina\ThreadTracker\Lib\site-packages\urllib3\__init__.py", line 8, in <module>
from .connectionpool import (
File "C:\Users\Christina\ThreadTracker\Lib\site-packages\urllib3\connectionpool.py", line 3, in <module>
import logging
SyntaxError: ("no viable alternative at input '='", ('C:\\Users\\Christina\\ThreadTracker\\Lib\\logging\\__init__.py', 261, 55, ' method_name, "method:", err, file=sys.stderr)\n'))
I'm extremely confused as to why I'm getting errors from the source code... And I've been having a heck of a time just trying to get the java-python integration to work.

cannot import name SharePointSite

I've got the same error message both on my desktop and on my Windows 2008 R2 server -
Here's the code -
from sharepoint import SharePointSite, basic_auth_opener
server_url = "http://sharepoint/"
site_url = server_url + "path/to/page/Forms/AllItems.aspx"
opener = basic_auth_opener(server_url, "acct", "password")
site = SharePointSite(site_url, opener)
for sp_list in site.lists:
print sp_list.id, sp_list.meta['Title']
When running it I get the following error -
Traceback (most recent call last):
File "C:\temp\sharepoint.py", line 1, in <module>
from sharepoint import SharePointSite, basic_auth_opener
File "C:\temp\sharepoint.py", line 1, in <module>
from sharepoint import SharePointSite, basic_auth_opener
ImportError: cannot import name SharePointSite
What's going on? The package is in the location -
C:\Python27\Lib\site-packages\sharepoint
I can import other packages just fine. for example, lxml works fine.
from lxml import etree
no problems.
You named your script sharepoint.py and that masks the library:
Traceback (most recent call last):
File "C:\temp\sharepoint.py", line 1, in <module>
from sharepoint import SharePointSite, basic_auth_opener
File "C:\temp\sharepoint.py", line 1, in <module>
from sharepoint import SharePointSite, basic_auth_opener
ImportError: cannot import name SharePointSite
Look at the filenames in the traceback, you can see that the script ends up importing itself; when Python starts your script it loads it as __main__, so importing sharepoint loads your own file one more time, at which point it fails to import itself again.
Rename your script to something else.

Categories

Resources