Cannot get any log information from pysimplesoap - python

I'm trying to use pysimplesoap (v.1.10) and getting what appears to be some kind of parsing error when executing a method request.
Stripped down version:
import pysimplesoap
soapURL = "https://site/path/to/soap"
namespace = "https://site/path/to/ns"
soapClient = pysimplesoap.client.SoapClient(location=soapURL + "?wsdl",namespace=namespace)
response = soapClient.getDocumentContent('1234567')
(python 2.7.8 btw)
Results in an error:
Traceback (most recent call last):
File ".\SOAPtest2.py", line 60, in <module>
response = soapClient.getDocumentContent('1234567')
File "build\bdist.win32\egg\pysimplesoap\client.py", line 139, in <lambda>
AttributeError: 'str' object has no attribute 'call'
However, the real question I have is that I am trying (unsuccessfully) to get logging working, but cannot see any output or determine/confirm what the XML structure it is sending/receiving. I might be able to diagnose the problem if I could see what it is receiving/trying to parse.
I have a gist of the code and the error I'm getting as well.
The odd part is that in my original script (before I stripped down to just some test code) I had a secondary logging instance and file handler and it worked just fine. So it seems specific to the pysimplesoap logging.
Any help would be greatly appreciated.
EDIT: Solution
Per KenK's recommendation, I modified my method call to be (documentId='1234567') and it worked. The script got past that error and I got a few log/debug lines in output. It seems that pysimplesoap simply has so few log/debug lines that none were reached prior to the error I was hitting.

Add the following code to your code:
import logging
logging.basicConfig(level=logging.DEBUG)
To fix the error you're getting, you need to specify an attribute name. Like this:
response = soapClient.getDocumentContent(name='1234567')
Replace name with whatever's defined for this function.

Related

"AttributeError: 'module' object has no attribute" - Can someone explain the meaning of this error message?

I'm trying to get the ODB library working. In the documentation at https://python-obd.readthedocs.io/en/latest/ it lists the following code:
import obd
connection = obd.OBD("/dev/ttyUSB0") # connects to USB or RF port
cmd = obd.commands.SPEED # select an OBD command (sensor)
response = connection.query(cmd) # send the command, and parse the response
print(response.value) # returns unit-bearing values thanks to Pint
print(response.value.to("mph")) # user-friendly unit conversions
When I put this in a file called test.py and I run it:
python2 test.py
I get the following error message:
Traceback (most recent call last):
File "test.py", line 1, in <module>
import obd
File "/home/ubuntu/obd.py", line 3, in <module>
AttributeError: 'module' object has no attribute 'OBD'
Stackoverflow comes up with several iterations of this error message, but none clearly explain the problem, only giving specific solutions to those libraries.
I guess it's obvious that I'm new to Python, and I'm having trouble interpreting this error message, even after several hours of writing several small Python programs. I am of course also interested in why the error message is so un-intuitive to a newcomer and where I can gain the common knowledge I might be missing, and I guess this is as good a case to discover that through as any.
So far I have figured out the following:
<module> refers to the name of my python script that I am trying to run.
The mistake I made at first, was to name my test.py file, initially obd.py. This conflicted with the import obd as it was trying to import the file itself - even after I deleted it! The reason was that when I tried to run it the first time, it created a file called obd.pyc - and even though obd.py was no longer there, import OBD found the initially created obd.pyc and tried to import that - which of course does not contain the OBD object from the library I was trying to use.
This is not the detailed answer I'm looking for, so please add a more detailed explanation - or a link to how Python compiling works, if you can.

InvalidAttributeValException running code

I am getting a syntax error in my code with Jython. Can anyone say what's wrong in the syntax? I am new to this language, don't have much of an idea.
Error Message :
WASX7017E: Exception received while running file "namespace.jy"; exception information: com.ibm.websphere.management.exception.InvalidAttributeValException: ADMG0012E: The attribute value for attribute integration/endpoint/account is not valid.
My Code:
import sys
nodeName =sys.argv[0]
serverName =sys.argv[1]
profilePath=sys.argv[2]
machineName=sys.argv[3]
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Main program
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
createNamespaceBinding(nodeName,serverName,profilePath,machineName)
I have added call to setJVMSystemProperties(), so it will ignore '/' in the name attribute, but am still facing the problem.
It worked for after adding this property file com.ibm.websphere.management.configservice.validateNames = false and then stopping and starting the server and then try to run jython script for namespace binding

cprofile compile error on python

using cProfile of python, I cprofiled my code, but I keep getting this error related with compile() and null character which I can't quite understand.
The error message is:
[cProfileV]: cProfile output available at http://127.0.0.1:4000
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/bin/cprofilev", line 9, in
load_entry_point('CProfileV==1.0.6', 'console_scripts', 'cprofilev')()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cprofilev.py", line 217, in main
code = compile(fp.read(), progname, 'exec')
TypeError: compile() expected string without null bytes
Is it a problem with my client code, or the server just isn't up?
Thank you in advance.
I believe the error is caused by a mismatch between versions of cprofile and cprofilev.
Cprofilev can be run directly using:
python -m cprofilev your_script.py
This has been asked before.
Anyhow, the error means you're recieving a string which you cannot read well, because it includes nulls. That means the server is up & responding but you cannot read the respond properly. That is because it's in another format, which is very likely JSON. try using the JSON module, included in python 2.6 and beyond; you could see some examples for it, here. If you'll provide us with your code, I can help you convert your application into a JSON-friendly one. :)

Python exception handling within module

Stackoverflow posts helped me a lot with Python, however I stuck on this one. I cannot figure out how to simply skip module if it has exceptions within it. Also, if it happens I like to alter one variable so rest of code would know to skip functionality related with that module.
I have main.py which is loading my module sms.py. Here you also see my attempt which does not work:
try:
import sms
except ImportError:
print "Ok, lets skip that module"
dont_use_sms = 1
Part of sms.py which causes exception looks following:
import gammu
sm = gammu.StateMachine()
sm.ReadConfig()
try:
sm.Init() # this one to be exact
except:
raise
when I run this I get following:
Traceback (most recent call last):
File "./main.py", line 10, in <module>
import sms
File "/path/to/sms.py", line 7, in <module>
sm.Init()
gammu.ERR_DEVICENOTEXIST: {'Text': u"Error opening device, it doesn't exist.", 'Code': 4, 'Where': 'Init'}
I have tried to alter exception by putting gammu.ERR_DEVICENOTEXIST as argument, however it didn't help.
I feel that that exception should be somehow handled by sms.py and properly forwarded to main.py, but cannot figure out how.
By the way, I know what causes gammu.ERR_DEVICENOTEXIST and that is not a problem. Question is about how to continue with rest of program if it appears.
That you for suggestions.
You can also change your main.py.
Instead of:
except ImportError:
you can say:
except:
And then it should continue.
PS: Naked except statements are not good style

Python: AttributeError: 'str' object has no attribute 'decompressUnknownOriginalSize'

First off, I'm not a programmer by any means. I just try to follow instructions.
So, I'm trying to use a script to decode game files. The problem is that I'm getting an error.
I've tried the script on 2 different machines wheres both give the same error. At the same time, I have friends using the exact same script w/o getting this error. Does anyone have any clue what is wrong?
Traceback (most recent call last):
File "F:\Frostbite Decoding\Decoding Files\bf4dumper.py", line 258, in <module>
if "tocRoot" in locals(): dumpRoot(tocRoot)
File "F:\Frostbite Decoding\Decoding Files\bf4dumper.py", line 249, in dumpRoot
dump(fname,targetDirectory)
File "F:\Frostbite Decoding\Decoding Files\bf4dumper.py", line 198, in dump
LZ77.decompressUnknownOriginalSize(catEntry.path,catEntry.offset,catEntry.size,targetPath)
AttributeError: 'str' object has no attribute 'decompressUnknownOriginalSize'
If you need anymore information, please let me know.
Python is saying that it is receiving a string and that there is no method for decompressUnknownOriginalSize. This sounds like the script needs to get some other data type or argument type than string. Look for where "decompressUnknownOriginalSize" is called and see what data type is being passed to that argument.

Categories

Resources