InvalidAttributeValException running code - python

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

Related

python WinError 32 and read() method

I am running the following code :
import os, configparser
config = configparser.ConfigParser()
config = config.read(r'C:\Users\ms\Desktop\3815_ticket\pconfig.txt')
portfolio_path=config['Data']['portfolio']
os.rename(portfolio_path,'bloop')
I obtain the following error :
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\ms\\Desktop\\\\data_lin\\portfolio.xlsx' -> 'bloop'
I read some old posts about this error, hence I modified it as follow :
with config.read(r'C:\Users\ms\Desktop\3815_ticket\pconfig.txt') as x :
portfolio_path=x['Data']['portfolio']
os.rename(portfolio_path,'bloop')
But now I obtain
AttributeError: __enter__
I then tried to avoid a with block; I copied my file paths stored in pconfig.txt and then deleted the configparser object, but I still obtain the [WinError 32] error.
Any help would be appreciated !
You don't need the with statement, and it can't help you here. The error AttributeError: __enter__ occurs because you are trying to use the with statement on an object that doesn't have __enter__ and __exit__ methods. See here for details: Explaining Python's '__enter__' and '__exit__'
The PermissionError has nothing to do with config.read(). Instead, it happens because of the os.rename(portfolio_path,'bloop') statement. The error message even tells you what the problem is. Microsoft Windows thinks that the spreadsheet with the file name portfolio_path (i.e. C:\Users\ms\Desktop\data_lin\\portfolio.xlsx) is already open. The proper thing to do then is to check if that file is indeed already open. If it is open, then if you can, close it and rerun your Python script. If it isn't, then find out why MS Windows thinks it's open.

Python/Q#: Module not found error, with .qs file in the same directory

Lately I started working with Q# and python as host language. I was working on a project and everything seemed fine. Suddenly I get the error "module not found" and I seem to get it in all my previous projects too.
So I have a directory: C:\Users\Username\Q#projects
In this folder I have 2 files: HostProtocol.py, which is the main file, and BB84.qs, which is the file from which I want to import.
The HostProtocol.py file looks like this:
import qsharp
from Quantum.BB84 import Run_BB84Protocol
Run_BB84Protocol.simulate()
The BB84.qs file looks like this:
namespace Quantum.BB84 {
open Microsoft.Quantum.Arrays;
open Microsoft.Quantum.Measurement;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Diagnostics;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Math;
function Run_BB84Protocol() Unit{... the code from the function...}
}
When I try to run HostProtocol.py I get the following error message:
Exception has occurred: ModuleNotFoundError
No module named 'Quantum'
File "C:\Users\Username\Q#projects\HostProtocol.py", line 3, in
from Quantum.BB84 import Run_BB84Protocol
And this is for all my previous projects too. It's very frustrating and I have no clue what could have caused it because it worked fine previously. Any help is definitely welcome!
If you have any Q# compilation errors in your Q# source file, your Q# operations and functions will not be available. Check your Python output for errors. When I run the sample code you provided, it reports a syntax error in the Q# code (there's a missing colon before the return type Unit):
fail: Microsoft.Quantum.IQSharp.Workspace[0]
QS3211: Invalid return type annotation. The argument tuple needs to be followed
by a colon and the return type of the callable.

Cannot get any log information from pysimplesoap

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.

Getting Started with Python: Attribute Error

I am new to python and just downloaded it today. I am using it to work on a web spider, so to test it out and make sure everything was working, I downloaded a sample code. Unfortunately, it does not work and gives me the error:
"AttributeError: 'MyShell' object has no attribute 'loaded' "
I am not sure if the code its self has an error or I failed to do something correctly when installing python. Is there anything you have to do when installing python like adding environmental variables, etc.? And what does that error generally mean?
Here is the sample code I used with imported spider class:
import chilkat
spider = chilkat.CkSpider()
spider.Initialize("www.chilkatsoft.com")
spider.AddUnspidered("http://www.chilkatsoft.com/")
for i in range(0,10):
success = spider.CrawlNext()
if (success == True):
print spider.lastUrl()
else:
if (spider.get_NumUnspidered() == 0):
print "No more URLs to spider"
else:
print spider.lastErrorText()
# Sleep 1 second before spidering the next URL.
spider.SleepMs(1000)
And what does that error generally
mean?
An Attribute in Python is a name belonging to an object - a method or a variable. An AttributeError means that the program tried to use an attribute of an object, but the object did not have the requested attribute.
For instance, string objects have the 'upper' attribute, which is a method that returns the uppercase version of the string. You could write a method that uses it like this:
def get_upper(my_string):
return my_string.upper()
However, note that there's nothing in that method to ensure that you have to give it a string. You could pass in a file object, or a number. Neither of those have the 'upper' attribute, and Python will raise an Attribute Error.
As for why you're seeing it in this instance, you haven't provided enough detail for us to work it out. Add the full error message to your question.
1) Put code in Try ... Except block. get exception details.
2) Could you tell StackTrace details means which line # and method thrown error
And also are you able to run other simple python scripts without any error. Means just try to run some sample script etc.

Google Appengine and Python exceptions

In my Google Appengine application I have defined a custom exception InvalidUrlException(Exception) in the module 'gvu'. Somewhere in my code I do:
try:
results = gvu.article_parser.parse(source_url)
except gvu.InvalidUrlException as e:
self.redirect('/home?message='+str(e))
...
which works fine in the local GAE development server, but raises
<type 'exceptions.SyntaxError'>: invalid syntax (translator.py, line 18)
when I upload it. (line 18 is the line starting with 'except')
The problem seems to come from the 'as e' part: if I remove it I don't get this exception anymore. However I would like to be able to access the raised exception. Have you ever encountered this issue? Is there an alternative syntax?
You probably have an older Python version on your server. except ExceptionType as varname: is a newer syntax. Previously you needed to simply use a comma: except ExceptionType, varname:.
I was getting the same error because I was using the pydoc command instead of the pydoc3 command on a python3 file that was using python3 print statements (print statements with parenthesis).
Just FYI, another possible cause for this error - especially if the line referenced is early in the script (like line 2) is line ending differences between Unix and Windows.
I was running Python on Windows from a Cygwin shell and got this error, and was really puzzled. I had created the file with "touch" before editing it.
I renamed the file to a temp file name, and copied another file (which I had downloaded from a Unix server) onto the original file name, then restored the contents via the temp file, and problem solved. Same exact file contents (on the screen anyway), only difference was where the file had originally been created.
Just wanted to post this in case anyone else ran across this error and was similarly puzzled.

Categories

Resources