SOAP API - Qname find fails with zeep and xmlsec on x509_data.find(QName(ns.DS, "X509Certificate")).text in centOS75 (python 3.8) - lxml

Versions I am using -
zeep==3.4.0
lxml==4.7.1
xmlsec==1.3.8
libxml2 = 2.9.2
Centos75
python 3.8.10
Error detail:
service_1 | Traceback (most recent call last):
service_1 | File "/app/wf_iccp/endpoints/home.py", line 59, in get_data_source_request
service_1 | return get_service(auth_cert=crt, auth_key=key).GetDataSource()
service_1 | File "/pyenv/versions/wf-iccp/lib/python3.8/site-packages/zeep/proxy.py", line 40, in __call__
service_1 | return self._proxy._binding.send(
service_1 | File "/pyenv/versions/wf-iccp/lib/python3.8/site-packages/zeep/wsdl/bindings/soap.py", line 118, in send
service_1 | envelope, http_headers = self._create(
service_1 | File "/pyenv/versions/wf-iccp/lib/python3.8/site-packages/zeep/wsdl/bindings/soap.py", line 95, in _create
service_1 | envelope, http_headers = client.wsse.apply(envelope, http_headers)
service_1 | File "/pyenv/versions/wf-iccp/lib/python3.8/site-packages/zeep/wsse/signature.py", line 104, in apply
service_1 | _sign_envelope_with_key_binary(
service_1 | File "/pyenv/versions/wf-iccp/lib/python3.8/site-packages/zeep/wsse/signature.py", line 287, in _sign_envelope_with_key_binary
service_1 | bintok.text = x509_data.find(QName(ns.DS, "X509Certificate")).text
service_1 | AttributeError: 'NoneType' object has no attribute 'text'
QName prints -
and ns.DS below refers to constant
print(QName(ns.DS, "X509Certificate"))
{http://www.w3.org/2000/09/xmldsig#}X509Certificate
xml certificate(I dumped the x509_data) and seems to be there.
<X509Data xmlns="http://www.w3.org/2000/09/xmldsig#" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser1="http://mastercard.com/sd/pc/service" xmlns:ser="http://mastercard.com/sd/pc2/service">
<X509Certificate>
CERTIFICATEVALUE
</X509Certificate>
<X509IssuerSerial>
<X509IssuerName>IUSSER_DETAILS</X509IssuerName>
<X509SerialNumber>SERIALNUMBER</X509SerialNumber>
</X509IssuerSerial>
</X509Data>
It was working before. Not sure what's going on . I tried using different versions of lxml but no luck. Any advice?
Thank you so much!!

Related

update a pandas dataset, using pandas.eval or df.apply

I have a pandas dataframe with a lot rows.
One of the columns, lets say WHERE_CLAUSE has some sql like conditions. So I created a new column which uses these conditions and translates it to python/pandas statements.
Eg: column 'WHERE_CLAUSE' has the value for a row like 'ACCOUNTING_PERIOD NOT IN (999)' , I am translating it to a pandas statement in a new column 'EVAL_EXPR' with value '''base_table.loc[(base_table.ACCOUNTING_PERIOD.isin([999]),"REPORT_TYPE_ID")] = "initial"'''.
Now this is a perfectly valid statement if I execute it directly and it does update the dataset.
The problem I face is, since it's a string, I am using
pandas.eval which has the above value and it fails
So this is what I tried:
eval_str ='''base_table.loc[(base_table.ACCOUNTING_PERIOD.isin([999]),"REPORT_TYPE_ID")] = "initial"'''
print(eval_str)
pd.eval(eval_str)
and this is the error I receive:
> base_table["REPORT_TYPE_ID"].apply(lambda x: "final" if
> base_table.ACCOUNTING_PERIOD.isin([999]))
>
> Traceback (most recent call last):
>
> File "C:\ProgramData\Anaconda3\lib\site-
> packages\IPython\core\interactiveshell.py", line 3331, in run_code
> exec(code_obj, self.user_global_ns, self.user_ns)
>
> File "<ipython-input-31-96405158714d>", line 9, in <module>
> pd.eval(eval_str)
>
> File
> "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\computation\eval.py",
> line 332, in eval
> parsed_expr = Expr(expr, engine=engine, parser=parser, env=env)
>
> File
> "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\computation\expr.py",
> line 764, in __init__
> self.terms = self.parse()
>
> File
> "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\computation\expr.py",
> line 781, in parse
> return self._visitor.visit(self.expr)
>
> File
> "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\computation\expr.py",
> line 375, in visit
> return visitor(node, **kwargs)
>
> File
> "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\computation\expr.py",
> line 381, in visit_Module
> return self.visit(expr, **kwargs)
>
> File
> "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\computation\expr.py",
> line 375, in visit
> return visitor(node, **kwargs)
>
> File
> "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\computation\expr.py",
> line 583, in visit_Assign
> raise SyntaxError("left hand side of an assignment must be a single name")
>
> File "<string>", line unknown SyntaxError: left hand side of an
> assignment must be a single name
I know pandas.apply doesn't take statements but expressions which is obviously what I am trying to execute. But how do I fix this?
I dont know how to tweak this ,so that I can use dataframe['column'].apply to avoid this issue.
Any suggestions much appreciated.
So to execute a dynamically generated python statement, I used this function 'exec'.It worked like charm!
Code Tried:
eval_str = '''base_table.loc[(base_table.ACCOUNTING_PERIOD.isin([999]),"REPORT_TYPE_ID")] = "initial"'''
exec(eval_Str)
Reference:
It was already answered in stackoverflow. Evaluating dynamically generated statements in Python

ST2ST is throwing an error when loading lat/log related to decimal

It appears that there is an odd non-displayable character in the value coming from VZW. The hex a0 prefixes the latitude value, and this throws off the method to convert a string to a decimal in the StGeolocationConverter class.
This is the most stack trace for error, and a VZW record id that can be investigated.
10:47:25.872 (12891843489)|USER_DEBUG|[1323]|ERROR|Remote Key: a0C0H00001RnioyUAB
(strk.StSiteTrigger: execution of BeforeInsert
caused by: strk.StException: Error in packaged trigger handler[strk.StSiteExtendibleTriggerHandler]:SObjectType[strk__Site__c]:Event[before_insert]Message[Invalid decimal: 39.98636000]:
Class.strk.StGeolocationConverter.setLatLong: line 97, column 1
Class.strk.StSiteExtendibleTriggerHandler.beforeInsert: line 36, column 1
Class.strk.StTriggerFactory.execute: line 396, column 1
Class.strk.StTriggerFactory.createAndExecuteHandler: line 253, column 1
Class.strk.StTriggerFactory.createAndExecutePackagedHandler: line 221, column 1
Class.strk.StTriggerFactory.executeTrigger: line 168, column 1
Trigger.strk.StSiteTrigger: line 17, column 1
Class.strk.StTriggerFactory.executeTrigger: line 174, column 1
Trigger.strk.StSiteTrigger: line 17, column 1 / CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY)[enter link description here][1]
Link to the zip file containing the logs: https://drive.google.com/open?id=1ddxspysuZq_8LNylUMlfshFBTy_YlYGy

How to pass the options JSON in the "Create Project" Post Rquest of the OpenRefine ReST-API?

I am currently trying to upload Excel tables (as .xls) to the OpenRefine (or OntoRefine) module of Ontotexts GraphDB. Since I had problems uploading the xls, I decided to first convert the xls file to a csv file and then upload it. Unfortunately, OpenRefine does not automatically recognize every time the file as CSV. So all data in each row is stored in a single column. E.g.:
--------------------------------------------------
| Col1, Col2, Col3, Col4 |
--------------------------------------------------
| Row11, Row12, Row13, Row14 |
--------------------------------------------------
| Row21, Row22, Row23, Row24 |
--------------------------------------------------
Instead of:
--------------------------------------------------
| Col1 | Col2 | Col3 | Col4 |
--------------------------------------------------
| Row11 | Row12 | Row13 | Row14 |
--------------------------------------------------
| Row21 | Row22 | Row23 | Row24 |
--------------------------------------------------
With the Post Request
POST /command/core/create-project-from-upload
a file format in the 'format' parameter and a json with the delimiter in 'options' parameter can be added to the POST request. However, this does not work either and the official OpenRefine documentation (https://github.com/OpenRefine/OpenRefine/wiki/OpenRefine-API) does not contain any hints as to the syntax of the 'options' JSON.
My current code looks like this:
import os
import xlrd
import csv
import requests
import re
xls_file_name_ext = os.path.basename('excel_file.xls')
# create the filename with path to the new csv file (path + name stays the same)
csv_file_path = os.path.dirname(xls_file_name_ext) + '/' + os.path.splitext(xls_file_name_ext)[0] + '.csv'
# remove all comma in xls file
xls_wb = xlrd.open_workbook(xls_file_name_ext)
xls_sheet = xls_wb.sheet_by_index(0)
for col in range(xls_sheet.ncols):
for row in range(xls_sheet.nrows):
_new_cell_val = str(xls_sheet.cell(row, col).value).replace(",", " ")
xls_sheet._cell_values[row][col] = _new_cell_val
# write to csv
with open(csv_file_path, 'w', newline='', encoding='utf-8') as csv_file:
c_w = csv.writer(csv_file, delimiter=',')
for row in range(xls_sheet.nrows):
c_w.writerow(xls_sheet.row_values(row))
ontorefine_server = 'http://localhost:7200/orefine'
# filename of csv as project name in OntoRefine
onterefine_project_name = os.path.splitext(os.path.basename(csv_file_path))[0]
# the required paraneters for the post request
ontorefine_data = {"project-name": onterefine_project_name,
"format": "text/line-based/*sv",
"options": {
"separator": ","
}
}
ontorefine_file = {'project-file': open(csv_file_path, "rb")}
# execute the post request
ontorefine_response = requests.post(
ontorefine_server + '/command/core/create-project-from-upload', data=ontorefine_data, files=ontorefine_file
)
I assume that I am passing the POST request parameters incorrectly.
It all depends on your input data, of course, but the formatting looks OK. Here's what OntoRefine does "behind the curtains" if you try to import from the UI. You can see the same payload for yourself by intercepting your network traffic:
{
"format": "text/line-based/*sv",
"options": {
"project-name":"Your-project-here",
"separator":","
}
Judging from that, it looks like the project-name location is the only difference. Here is a curl command which does the same:
curl 'http://localhost:7200/orefine/command/core/importing-controller?controller=core%2Fdefault-importing-controller&jobID=1&subCommand=create-project' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' --data 'format%3Dtext%2Fline-based%2F*sv%26options%3D%7B%22separator%22%3A%22%2C%22%22projectName%22%3A%22Your-project-name%22%7D'

Controlling the parameters of python cvxopt solver while performing SDP

I have a python code to solve the following simple Semidefinite Program:
Input: Two Real 4 x 4 matrices, A and B
Output: 1 - q where q = maximum over all p, such that:
0 < p < 1
A - p B is positive semi-definite
When I view an instance of the above problem in verbose mode, the Python code produces the following message.
10:Channel_Flow pavithran$ python stackoverflow_sdp.py
*** Dualizing the problem... ***
[ #################################################################### ] 100%
[ #################################################################### ] 100%
--------------------------
cvxopt CONELP solver
--------------------------
pcost dcost gap pres dres k/t
0: 5.5546e-01 5.5546e-01 2e+01 3e+00 2e+00 1e+00
1: -4.3006e-01 -7.3065e-02 3e+00 6e-01 3e-01 6e-01
2: -4.9751e+01 2.1091e+00 9e+03 2e+01 8e+00 6e+01
3: -3.4525e+02 7.6511e-02 9e+03 2e+00 1e+00 3e+02
4: -3.4496e+04 7.6337e-02 9e+05 2e+00 1e+00 3e+04
5: -3.4496e+06 7.6337e-02 9e+07 2e+00 1e+00 3e+06
6: -3.4496e+08 7.6337e-02 9e+09 2e+00 1e+00 3e+08
Certificate of dual infeasibility found.
cvxopt status: dual infeasible
*** Dual Solution not found
Traceback (most recent call last):
File "stackoverflow_sdp.py", line 42, in <module>
simple_sdp(A,B)
File "stackoverflow_sdp.py", line 31, in simple_sdp
prob.solve(verbose = 2)
File "/Library/Python/2.7/site-packages/picos/problem.py", line 4246, in solve
raise Exception("\033[1;31m no Primals retrieved from the dual problem \033[0m")
Exception: no Primals retrieved from the dual problem
10:Channel_Flow pavithran$
There are several parameters. I would like to know if it is possible to specify a bound on any of the parameters, to terminate the SDP, except specifying the maximum number of iterations. For instance, can we specify a limit on "gap", "pres", "dres"?

Error matplotlib.lines.Line2D object at 0x025B8350

>>> import pylab as pl
>>> x = np.linspace(0,4*np.pi, 100)
>>> pl.plot(x, np.sin(x))
[<matplotlib.lines.Line2D object at 0x025B8350>]
after install numpy, scipy, sympy, matplotlib, ipython
---------------------------------------------------------------------------
TypeError Python 2.7.3: C:\Python27\python.exe
Fri Sep 28 09:59:01 2012
A problem occured executing Python code. Here is the sequence of function
calls leading up to the error, with the most recent (innermost) call last.
C:\Python27\scripts\ipython.py in <module>()
13
14 [or simply IPython.Shell.IPShell().mainloop(1) ]
15
16 and IPython will be your working environment when you start python. The final
17 sys.exit() call will make python exit transparently when IPython finishes, so
18 you don't have an extra prompt to get out of.
19
20 This is probably useful to developers who manage multiple Python versions and
21 don't want to have correspondingly multiple IPython versions. Note that in
22 this mode, there is no way to pass IPython any command-line options, as those
23 are trapped first by Python itself.
24 """
25
26 import IPython.Shell
27
---> 28 IPython.Shell.start().mainloop()
global IPython.Shell.start.mainloop = undefined
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
C:\Python27\lib\site-packages\IPython\Shell.pyc in start(user_ns=None)
1244
1245 # New versions of pygtk don't need the brittle threaded support.
1246 th_mode = check_gtk(th_mode)
1247 return th_shell[th_mode]
1248
1249
1250 # This is the one which should be called by external code.
1251 def start(user_ns = None):
1252 """Return a running shell instance, dealing with threading options.
1253
1254 This is a factory function which will instantiate the proper IPython shell
1255 based on the user's threading choice. Such a selector is needed because
1256 different GUI toolkits require different thread handling details."""
1257
1258 shell = _select_shell(sys.argv)
-> 1259 return shell(user_ns = user_ns)
1260
1261 # Some aliases for backwards compatibility
1262 IPythonShell = IPShell
1263 IPythonShellEmbed = IPShellEmbed
1264 #************************ End of file <Shell.py> ***************************
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
C:\Python27\lib\site-packages\IPython\Shell.pyc in __init__(self=<IPython.Shell.IPShell instance>, argv=None, user_ns=None, user_global_ns=None, debug=1, shell_class=<class 'IPython.iplib.InteractiveShell'>)
58 # Default timeout for waiting for multithreaded shells (in seconds)
59 GUI_TIMEOUT = 10
60
61 #-----------------------------------------------------------------------------
62 # This class is trivial now, but I want to have it in to publish a clean
63 # interface. Later when the internals are reorganized, code that uses this
64 # shouldn't have to change.
65
66 class IPShell:
67 """Create an IPython instance."""
68
69 def __init__(self,argv=None,user_ns=None,user_global_ns=None,
70 debug=1,shell_class=InteractiveShell):
71 self.IP = make_IPython(argv,user_ns=user_ns,
72 user_global_ns=user_global_ns,
---> 73 debug=debug,shell_class=shell_class)
global For = undefined
global more = undefined
global details = undefined
global see = undefined
global the = undefined
global __call__ = undefined
global method = undefined
global below. = undefined
74
75 def mainloop(self,sys_exit=0,banner=None):
76 self.IP.mainloop(banner)
77 if sys_exit:
78 sys.exit()
79
80 #-----------------------------------------------------------------------------
81 def kill_embedded(self,parameter_s=''):
82 """%kill_embedded : deactivate for good the current embedded IPython.
83
84 This function (after asking for confirmation) sets an internal flag so that
85 an embedded IPython will never activate again. This is useful to
86 permanently disable a shell that is being called inside a loop: once you've
87 figured out what you needed from it, you may then kill it and the program
88 will then continue to run without the interactive shell interfering again.
C:\Python27\lib\site-packages\IPython\ipmaker.pyc in make_IPython(argv=[r'C:\Python27\scripts\ipython.py'], user_ns=None, user_global_ns=None, debug=1, rc_override=None, shell_class=<class 'IPython.iplib.InteractiveShell'>, embedded=False, **kw={})
506 # tweaks. Basically options which affect other options. I guess this
507 # should just be written so that options are fully orthogonal and we
508 # wouldn't worry about this stuff!
509
510 if IP_rc.classic:
511 IP_rc.quick = 1
512 IP_rc.cache_size = 0
513 IP_rc.pprint = 0
514 IP_rc.prompt_in1 = '>>> '
515 IP_rc.prompt_in2 = '... '
516 IP_rc.prompt_out = ''
517 IP_rc.separate_in = IP_rc.separate_out = IP_rc.separate_out2 = '0'
518 IP_rc.colors = 'NoColor'
519 IP_rc.xmode = 'Plain'
520
--> 521 IP.pre_config_initialization()
522 # configure readline
523
524 # update exception handlers with rc file status
525 otrap.trap_out() # I don't want these messages ever.
526 IP.magic_xmode(IP_rc.xmode)
527 otrap.release_out()
528
529 # activate logging if requested and not reloading a log
530 if IP_rc.logplay:
531 IP.magic_logstart(IP_rc.logplay + ' append')
532 elif IP_rc.logfile:
533 IP.magic_logstart(IP_rc.logfile)
534 elif IP_rc.log:
535 IP.magic_logstart()
536
C:\Python27\lib\site-packages\IPython\iplib.pyc in pre_config_initialization(self=<IPython.iplib.InteractiveShell object>)
820 self.user_ns, # globals
821 # Skip our own frame in searching for locals:
822 sys._getframe(depth+1).f_locals # locals
823 ))
824
825 def pre_config_initialization(self):
826 """Pre-configuration init method
827
828 This is called before the configuration files are processed to
829 prepare the services the config files might need.
830
831 self.rc already has reasonable default values at this point.
832 """
833 rc = self.rc
834 try:
--> 835 self.db = pickleshare.PickleShareDB(rc.ipythondir + "/db")
global Optional = undefined
global inputs = undefined
836 except exceptions.UnicodeDecodeError:
837 print "Your ipythondir can't be decoded to unicode!"
838 print "Please set HOME environment variable to something that"
839 print r"only has ASCII characters, e.g. c:\home"
840 print "Now it is",rc.ipythondir
841 sys.exit()
842 self.shadowhist = IPython.history.ShadowHist(self.db)
843
844 def post_config_initialization(self):
845 """Post configuration init method
846
847 This is called after the configuration files have been processed to
848 'finalize' the initialization."""
849
850 rc = self.rc
C:\Python27\lib\site-packages\IPython\Extensions\pickleshare.pyc in __init__(self=PickleShareDB('C:\Documents and Settings\martinhylee\_ipython\db'), root=u'C:\\Documents and Settings\\martinhylee\\_ipython/db')
38 import cPickle as pickle
39 import UserDict
40 import warnings
41 import glob
42
43 def gethashfile(key):
44 return ("%02x" % abs(hash(key) % 256))[-2:]
45
46 _sentinel = object()
47
48 class PickleShareDB(UserDict.DictMixin):
49 """ The main 'connection' object for PickleShare database """
50 def __init__(self,root):
51 """ Return a db object that will manage the specied directory"""
52 self.root = Path(root).expanduser().abspath()
---> 53 if not self.root.isdir():
54 self.root.makedirs()
55 # cache has { 'key' : (obj, orig_mod_time) }
56 self.cache = {}
57
58
59 def __getitem__(self,key):
60 """ db['key'] reading """
61 fil = self.root / key
62 try:
63 mtime = (fil.stat()[stat.ST_MTIME])
64 except OSError:
65 raise KeyError(key)
66
67 if fil in self.cache and mtime == self.cache[fil][1]:
68 return self.cache[fil][0]
TypeError: _isdir() takes exactly 1 argument (0 given)
**********************************************************************
Oops, IPython crashed. We do our best to make it stable, but...
A crash report was automatically generated with the following information:
- A verbatim copy of the crash traceback.
- A copy of your input history during this session.
- Data on your current IPython configuration.
It was left in the file named:
'C:\Documents and Settings\martinhylee\_ipython\IPython_crash_report.txt'
If you can email this file to the developers, the information in it will help
them in understanding and correcting the problem.
You can mail it to: Fernando Perez at fperez.net#gmail.com
with the subject 'IPython Crash Report'.
If you want to do it now, the following command will work (under Unix):
mail -s 'IPython Crash Report' fperez.net#gmail.com < C:\Documents and Settings\martinhylee\_ipython\IPython_crash_report.txt
To ensure accurate tracking of this issue, please file a report about it at:
https://bugs.launchpad.net/ipython/+filebug
Error in sys.excepthook:
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\IPython\CrashHandler.py", line 157, in __call__
report.write(self.make_report(traceback))
File "C:\Python27\lib\site-packages\IPython\CrashHandler.py", line 215, in make_report
rpt_add('BZR revision : %s \n\n' % Release.revision)
AttributeError: 'module' object has no attribute 'revision'
Original exception was:
Traceback (most recent call last):
File "C:\Python27\scripts\ipython.py", line 28, in <module>
IPython.Shell.start().mainloop()
File "C:\Python27\lib\site-packages\IPython\Shell.py", line 1259, in start
return shell(user_ns = user_ns)
File "C:\Python27\lib\site-packages\IPython\Shell.py", line 73, in __init__
debug=debug,shell_class=shell_class)
File "C:\Python27\lib\site-packages\IPython\ipmaker.py", line 521, in make_IPython
IP.pre_config_initialization()
File "C:\Python27\lib\site-packages\IPython\iplib.py", line 835, in pre_config_initialization
self.db = pickleshare.PickleShareDB(rc.ipythondir + "/db")
File "C:\Python27\lib\site-packages\IPython\Extensions\pickleshare.py", line 53, in __init__
if not self.root.isdir():
TypeError: _isdir() takes exactly 1 argument (0 given)
Try this:
from pylab import *
x = np.linspace(0.4 * np.pi, 100)
plot(x, np.sin(x))
show()