OSError: [Errno 22] Invalid argument Getting invalid argument while parsing xml in python - python-3.x

I have below xml where i am trying extract value which is required
xml = '<s:Envelope xmlns:s="schemas.xmlsoap.org/soap/envelope/"><s:Body><GetService xmlns="abc.com/Service">
<GetService xmlns:a="abc.com" xmlns:i="www.w3.org/2001/XMLSchema-instance">
<a:EnvironmentName>test</a:EnvironmentName><a:HasUpdates>true</a:HasNewUpdates><a:active>false</a:active><a:Time>13:37:22</a:Time><a:ServiceUrisString><s><u t="1" n="net://abc.com/" i="net.tcp://abc.com/" /><u t="2"
" /></s></a:ServiceUrisString></GetService></GetServiceRegistryResponse></s:Body></s:Envelope>
'
What iam looking for is to get the value for 'active' and 'time' from above xml
active=false
time=13:37:22
Below is the code
import xml.etree.ElementTree as ET
tree=ET.parse(xml)
print(tree)
But the parsing not working as expected
Below I am getting following error
OSError: [Errno 22] Invalid argument:
SO how to resolve this issue?

ET.parse() is a function for reading xml from disk
try ET.fromstring(xml)

Related

Maya 2023 pymel I can't access mel2py with python3

I get this error and I think it's because of python3
Error: AttributeError: file C:\Program Files\Autodesk\Maya2023\Python\lib\site-packages\pymel\tools\mel2py\melparse.py line 438: 'str' object has no attribute 'lineno'
import pymel.tools.mel2py as mel2py
pythonCode = mel2py.mel2pyStr( """
setDrivenKeyframe -currentDriver pCube1.translateY pCube2.translateX;
setDrivenKeyframe -currentDriver pCube1.translateY pCube2.translateY;
setDrivenKeyframe -currentDriver pCube1.translateY pCube2.translateZ;
""",pymelNamespace='pm')
print( pythonCode )
I believe the issue is down to how you're formatting the mel command string. If you use the code below it should function:
import pymel.tools.mel2py as mel2py
mel_command = 'setDrivenKeyframe "-currentDriver pCube1.translateY pCube2.translateX";setDrivenKeyframe "-currentDriver pCube1.translateY pCube2.translateY";setDrivenKeyframe "-currentDriver pCube1.translateY pCube2.translateZ";'
pythonCode = mel2py.mel2pyStr(mel_command, pymelNamespace='pm')
print(pythonCode)
A simple solution is to launch a maya2019 or maya2018 version prior to maya2022 and use mel2py there.

Exception Type: <class 'OSError'>. Arguments: [[WinError 1155] No application is associated with the specified file for this operation:

I am trying to print pdf using FPDF. The pdf is generating successfully for every order but whenever I am trying to print the pdf by using os.startfile it gives me the os error. I am using fpdf 1.7.2 version. I have attached the code and also the error. Can anyone suggest me how to solve this things?
try:
gv.error_log("inside try block")
gv.error_log("===============self.print_file=============")
os.startfile(self.print_file, "print")
gv.error_log("end try block")
except Exception as e:
exception_message = str(e)
exception_type, exception_object, exception_traceback = sys.exc_info()
filename = os.path.split(exception_traceback.tb_frame.f_code.co_filename)[1]
gv.error_log(str('Raised error due to ' + (
f"An Exception Occured. \n Exception Type: {str(exception_type)}. Arguments: [{exception_message}]. File Name: {filename}, Line no: {exception_traceback.tb_lineno}")))
> --> Error: Raised error due to An Exception Occured.
Exception Type: <class 'OSError'>. Arguments: [[WinError 1155] No application is associated with the specified file for this operation.

Getting FileNotFoundError when calling python coded file from robot framework

I am trying to write an automation code for picking up different environment values for execution of my testcases based on the value I pass for environment.
Here is the code I tried :
# env.robot
*** Settings ***
Variables setup.py stage01
*** Test Cases ***
Print values
log to console ${data}
# setup.py
from robot.libraries.BuiltIn import BuiltIn
import xlrd
def get_variables(env):
file_location = "values.xlsx"
workbook = xlrd.open_workbook(file_location)
sheet = workbook.sheet_by_name(env)
print("Env : " + sheet.name)
data = [[sheet.cell_value(r, c) for c in range(sheet.ncols)] for r in range(sheet.nrows)]
print(data)
BuiltIn().log_to_console(data)
return data
Response I am getting :
[ ERROR ] Error in file 'D:\env.robot': Processing variable file 'D:\setup2.py' with arguments [ stage01 ]
failed: FileNotFoundError: [Errno 2] No such file or directory: 'values.xlsx'
values.xlsx is present in the same directory with .py and .robot file
I want to get the data from values.xlsx file based on the value of env variable and use the values in robot testcases.
Please suggest what I need to modify or any other approach would also do.

How to retreive original folder contents from Appium pull_folder output?

Based on the appium doc at http://appium.io/docs/en/commands/device/files/pull-folder/ a folder can be pulled following way
folder_base64 = self.driver.pull_folder('/path/to/device/foo.bar')
As per the doc the response folder_base64 is : "A string of Base64 encoded data, representing a zip archive of the contents of the requested folder."
So, based on my understanding of the above, i tried followings(A to D) which did not work.
A)
base64 decoding of the folder_base64
Unzipping the decoded output
decoded_base64 = base64.b64decode(folder_base64)
folder_base64 = ZipFile.extractall(decoded_base64)
this fails with following error:
zipfile.py", line 1493, in extractall
AttributeError: 'bytes' object has no attribute 'namelist'
B)
base64 decoding of the folder_base64
zipping the decoded output
unzipping
decoded_base64 = base64.b64decode(folder_base64)
zipfile.ZipFile('out.zip', mode='w').write(decoded_base64)
fails with following error at step 2:
zipfile.py", line 484, in from_file
st = os.stat(filename)
ValueError: stat: embedded null character in path
C)
unzipping the folder_base64
base64 decoding of the output
unzipped_base64 = ZipFile.extractall(folder_base64)
decoded_base64 = base64.b64decode(unzipped_base64)
fails at step 1 with following error
zipfile.py", line 1493, in extractall
AttributeError: 'str' object has no attribute 'namelist'
D)
base64 decoding of the folder_base64
read the file as zip file
extract the files
decoded_base64 = base64.b64decode(folder_base64)
zip_folder = zipfile.ZipFile(decoded_base64, 'r')
ZipFile.extractall(zip_folder, "./mp3_files")
fails with following error:
zipfile.py", line 241, in _EndRecData
fpin.seek(0, 2)
AttributeError: 'bytes' object has no attribute 'seek'
E)
Finally following worked, but i am wondering why it had to be routed via a temp file to make it work? Also, is there a better way/more direct way to handle appium pull_folder output?
decoded_base64 = base64.b64decode(folder_base64)
with SpooledTemporaryFile() as tmp:
tmp.write(decoded_base64)
archive = ZipFile(tmp, 'r')
ZipFile.extractall(archive, "./mp3_files")
Note: following python packages are used in above code snippets
import zipfile
from tempfile import SpooledTemporaryFile

Netsuite CSV import(An unexpected error has occurred)

Below is the sample code, i am using in CSV Import process.
var createJob = nlapiCreateCSVImport();
createJob.setMapping("CUSTIMPORTcust_pay");
createJob.setPrimaryFile("Data_string");
createJob.setOption("jobName", "Test imports");
var JobId = nlapiSubmitCSVImport(createJob);
nlapiSubmitCSVImport function is returning JobId without any error, but in job status page[UI] it showing status is failed and in Message field it showing "An unexpected error has occurred", CSV Response field also empty. when i try this by running the above code with same data again, some time it is successfully imported and some time it got failed, with showing message "An unexpected error has occurred"
Please see setPrimaryFile(file).
Where file is either:
The internal ID, as shown in the file cabinet, of the CSV file containing data to be imported, referenced by nlapiLoadFile. For example:
.setPrimaryFile(nlapiLoadFile(73))
Raw string of the data to be imported.
You are passing in a raw string of "Data_string".

Resources