Dears,
first of all this is the first time I ask a question on Stackoverflow so forgive me if I'm not following the right way to do this.
I kindly ask for your help as I'm facing an issue with win32com.
I'm trying to connect to SAP GUI in order to automate certain tasks.
import win32com.client
SapGuiAuto = win32com.client.GetObject('SAPGUI')
I get the following error (until yesterday everything was working fine..):
Traceback (most recent call last):
File "C:/Users/xxxxx/AppData/Roaming/JetBrains/PyCharmCE2020.1/scratches/PySAPscript.py", line 157, in <module>
SAP_OP()
File "C:/Users/xxxxx/AppData/Roaming/JetBrains/PyCharmCE2020.1/scratches/PySAPscript.py", line 18, in SAP_OP
SapGuiAuto = win32com.client.GetObject('SAPGUI')
File "C:\Users\xxxxx\PycharmProjects\yyyyyy\venv\lib\site-packages\win32com\client\__init__.py", line 72, in GetObject
return Moniker(Pathname, clsctx)
File "C:\Users\xxxxxx\PycharmProjects\yyyyyyy\venv\lib\site-packages\win32com\client\__init__.py", line 87, in Moniker
moniker, i, bindCtx = pythoncom.MkParseDisplayName(Pathname)
pywintypes.com_error: (-2147221020, 'Invalid syntax.', None, None)
I've found some documentation about this issue which suggests using pythoncom.CoInitialize():
Using win32com with multithreading
However I can't figure out how to use this function for my purpose.
Thank you for your help!
Considering, that you have variables (SAP_Path, SAP_system_id, SAP_group) or (SAP_Path,
SAP_sid, SAP_instance_no) instead...
shell = win32com.client.Dispatch("WScript.Shell")
call(SAP_Path + " /R/" + SAP_system_id + "/G/" + SAP_group)
OR: call(SAP_Path + " " + SAP_sid + " " + SAP_instance_no)
sap_gui_obj = win32com.client.GetObject("SAPGUI")
application = sap_gui_obj.GetScriptingEngine
connection = application.children(application.connections.count - 1)
session = connection.children(0)
session.findById("wnd[0]").maximize()
Then connect to your base.
I also encountered this problem recently.
The startup permissions of sap and python are not the same.
For example, both of these should be run with administrator rights, or run with ordinary user rights.
I do not guarantee that this method will solve your problem, but you can try :)
I had the same issue when trying to run SAP GUI Script triggered from Flask (desktop) application. Solution that works for me is to embrace the code operating with SAP GUI with pythoncom.CoInitialize() and pythoncom.CoUinitialize() statements:
def display_document():
import win32com.client
import pythoncom
pythoncom.CoInitialize()
sap_gui = win32com.client.GetObject("SAPGUI")
sap_app = sap_gui.GetScriptingEngine
sap_conn = sap_app.Children(0)
sap_session = sap_conn.Children(0)
sap_session.StartTransaction("FB03")
pythoncom.CoUninitialize()
Related
from Bio import Entrez, __version__
print('Biopython version : ', __version__)
id_list = ["NC_045512.2", "ON248099.1", "ON248101.1", "ON248104.1", "ON248107.1", "ON248108.1", "ON248109.1", "ON248110.1", "ON248114.1", "ON247234.1", "ON247236.1", "ON247240.1", "ON247242.1", "ON247243.1", "ON247244.1", "ON247245.1", "ON247246.1", "ON247247.1", "ON247248.1"]
try:
print ("Downloading "+str(id_list[ax]))
net_handle = Entrez.efetch(db="nucleotide", id=id_list[ax], rettype="fasta", retmode="text")
net_handle_gb = Entrez.efetch(db="nucleotide", id=id_list[ax], rettype="gbwithparts", retmode="text")
except (IOError):
print ("Waiting")
sleep (30)
tell.app( 'Terminal', 'do script "' + command+ ' && ' + "python3 'All Covid SSR.py'" +'"')
I'm using this try block to download files from NCBI API. Up to this point, the try block was working and the exception was handled as given here. Now it isn't. The code gets stuck in the try section. Returns no errors or exceptions, so it doesn't trigger the exception handler.
I've set max_tries = 1, sleep_between_tries = 1 and got the personal API_Key too.
For context, I'm using the exceptions block to restart the downloading code on Mac Terminal.
I need the try and except section to automatically restart the script when Entrez.efetch returns an error. There isn't any error. The code just gets stuck after
print ("Downloading "+str(id_list[ax]))
Any suggestions are welcome.
P.S. I thought of changing the default timeout for requests.get because that's the module Entrez uses to access the NCBI API. Haven't found a way to do that. (There is no timeout variable that you can set in the efetch module.)
An explanation would be great!
Hello I am trying to run the python script below
from selenium import webdriver
driver=webdriver.Chrome('C:\\Users\\Julian\\Downloads\\chromedriver_win32\\chromedriver.exe')
driver.get('https://www.youtube.com')
Upon Running it I am taken to a file named service.py and pointed to the the following
:Exceptions:
- WebDriverException : Raised either when it can't start the service
or when it can't connect to the service
"""
try:
cmd = [self.path]
cmd.extend(self.command_line_args())
self.process = subprocess.Popen(cmd, env=self.env,d
close_fds=(platform.system() != 'Windows'),
stdout=self.log_file,
stderr=self.log_file,
stdin=PIPE)
The particular line highlighted
close_fds=(platform.system() != 'Windows'),
Can someone point me in the direction of what I am supposed to do or change? Any help is strongly appreciated!
I just had to remove the d. Must have typed it by accident.
I'm trying to use pyusb over usblib1.0 to read the data from an old Ps2 mouse using a Ps2 to USB adapter that represents it as a HID device.
I am able to access the device, but when I try to send it the GET_REPORT request over control transfer, it shows me this error:
[Errno None] b'libusb0-dll:err [claim_interface] could not claim interface 0, win error: The parameter is incorrect.\r\n'
Here is my code:
import usb.core as core
import time
from usb.core import USBError as USBError
dev = core.find(idVendor=0x13ba, idProduct=0x0018, address=0x03)
interface = 0
endpoint = dev[0][(interface, 0)][0]
dev.set_configuration()
collected = 0
attempts = 50
while collected < attempts:
try:
print(dev.ctrl_transfer(0b10100001, 0x01, wValue=100, data_or_wLength=64))
collected += 1
except USBError as e:
print(e)
time.sleep(0.1)
I'm using python 3.x in windows 10 (Lenovo g-510 if it matters to anyone)
The driver I installed is a usblib-win32 using Zadig
Any help will be appreciated!
Thanks
EDIT:
Tried using WIN-USB so that It'll work with usblib-1.0
It didn't find the device. Returned None from the usb.core.fןnd() function
Continuing with WIN-USB with usblib-1.0, I successfully found the device, but no it appears to have no configuration.
dev.set_configuration()
returns:
File "C:\Users\Idan Stark\AppData\Local\Programs\Python\Python36-32\lib\site-packages\usb\backend\libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 2] Entity not found
Any help will be appreciated, in usblib-1.0 or usblib-0.1, anything to make this work! Thank you!
I am trying to create JMSQueue with following code but getting error on
cd ('/JMSSystemResources/BAMJMSSystemResource/JMSResource/BAMJMSSystemResource/Queues/SampleQueue')
When I connected to server runtimeand check I can see JMS Module is not available, but from Admin Console I can clearly see it's (JMS Module BAMJMSSystemResource) available, also it's not giving errors for
Note : I am creating JMS module before calling createJMSQueue function )
def createJMSQueue(jmsQueueName, jmsModuleName, jndiName, subdeployment):
print ' Creating Queue '+jmsQueueName
cd('/')
cd("/JMSSystemResources/"+jmsModuleName+"/JMSResource/"+jmsModuleName)
cmo.createQueue(jmsQueueName)
print('DEBUG >> '+jmsModulePath+'/Queues/'+jmsQueueName)
cd("/JMSSystemResources/"+jmsModuleName+"/JMSResource/"+jmsModuleName+'/Queues/'+jmsQueueName)
set('JNDIName',jndiName)
set('SubDeploymentName',subdeployment)
cd('/JMSSystemResources/'+jmsModuleName+'/SubDeployments/'+subdeployment)
cmo.addTarget(getMBean('/JMSServers/BAMMonitoringServer'))
Error is ,
Starting an edit session ...
Started edit session, please be sure to save and activate your
changes once you are done.
*** Creating JMS Queues ....
Creating Queue SampleQueue
DEBUG >> JMSSystemResources/BAMJMSSystemResource/JMSResource/BAMJMSSystemResource/Queues/SampleQueue
No stack trace available.
Problem invoking WLST - Traceback (innermost last):
File "/home/oracle/JMSConfigurations.py", line 188, in ?
File "/home/oracle/JMSConfigurations.py", line 77, in createJMSQueue
File "<iostream>", line 182, in cd
File "<iostream>", line 1847, in raiseWLSTException
WLSTException: Error cding to the MBean
Would really like to understand what's wrong ?
Shanaka, there could be problem in 'cd' command given after the DEBUG statement. You can give the cd line as below:
cd(jmsModulePath+'/Queues/'+jmsQueueName)
You can also get some more clarity on JMS module creation using WLST by Examples
This section of script looks fine except mix of double and single quote in " cd("/JMSSystemResources/"+jmsModuleName+"/JMSResource/"+jmsModuleName+'/Queues/'+jmsQueueName)"
and assigning target "cmo.addTarget()" , you dont need to target queue if sub-deployment is already targeted to JMS server.
You can check if your edit session of creating JMS module,Sub deployment, target JMS module to server and sub deployment to JMS server is activated successfully.
Then this Queue creation should work fine.
regards,
Kshitij
That can mean that the JMS you are trying to create already exists in WebLogic. Confirm that the JMS names are not existing ones.
I share with you my correct code:
def create_jms_object(name, module, subdeployment, type):
cd('/JMSSystemResources/'+module+'/JMSResource/'+module)
myob=create(name, type)
myob.setJNDIName("jms/"+name)
myob.setSubDeploymentName(subdeployment)
and I call the function here:
queue_name = queue['name']
sub_depl_name = queue['sub_deployment']
if(not_exists_jms_ud_qeue(jms_module_name, queue_name)):
print 'Creating queue '+queue_name
create_jms_object(queue_name, jms_module_name, sub_depl_name, 'UniformDistributedQueue')
print 'Created queue '+queue_name
else:
print 'UniformDistributedQueue ' + queue_name + ' already exists'
cmo = cd('/JMSSystemResources/'+jms_module_name+'/JMSResource/'+jms_module_name+'/UniformDistributedQueues/'+queue_name+'/DeliveryFailureParams/'+queue_name)
redelivery_limit = queue.get('redelivery_limit',-1)
set('RedeliveryLimit', redelivery_limit)
errorDestinationName = queue.get('error_destination', None)
if (errorDestinationName is not None):
errorDestination = getMBean('/JMSSystemResources/'+jms_module_name+'/JMSResource/'+jms_module_name+'/UniformDistributedQueues/'+errorDestinationName)
set('ErrorDestination', errorDestination)
print 'Dead letter queue set to: '+errorDestinationName
else:
cmo.unSet('ErrorDestination')
print 'Dead letter queue unset'
cd('/JMSSystemResources/'+jms_module_name+'/JMSResource/'+jms_module_name+'/UniformDistributedQueues/'+queue_name+'/DeliveryParamsOverrides/'+queue_name)
redelivery_delay = queue.get('redelivery_delay',-1)
set('RedeliveryDelay', redelivery_delay)
time_to_deliver = queue.get('time_to_deliver',-1)
set('TimeToDeliver', time_to_deliver)
where the queue object is the following:
{
"name" : "events_reg_queue",
"sub_deployment" : "Registry-SD",
"redelivery_limit" : 1
}
and the following utility function:
def not_exists_jms_ud_qeue(jmsModuleName, jmsResourceName):
try:
myMBean = getMBean('/JMSSystemResources/'+jmsModuleName+'/JMSResource/'+jmsModuleName+'/UniformDistributedQueues/'+jmsResourceName)
if (myMBean is None):
return true
return false
except:
return true
Did you try traversing the path manually ?
You can traverse the /edit location using the wlst command line.
Use cd("") and ls() to traverse and list those properties you created.
Im trying to call a command from wsadminlib.py to change the initialHeapSize and the maximumHeapSize in a script. But unfortunately my jython (and general scripting knowledge) is still total newbie.
Im using the call
#Change Java Heap Size
setJvmProperty(nodeName,serverName,maximumHeapsize -2048 ,initialHeapSize -2048)
Which should relate to the command in the wsadminlib.py library
def setJvmProperty(nodename,servername,propertyname,value):
"""Set a particular JVM property for the named server
Some useful examples:
'maximumHeapSize': 512 ,
'initialHeapSize':512,
'verboseModeGarbageCollection':"true",
'genericJvmArguments':"-Xgcpolicy:gencon -Xdump:heap:events=user -Xgc:noAdaptiveTenure,tenureAge=8,stdGlobalCompactToSatisfyAllocate -Xconcurrentlevel1 -Xtgc:parallel",
"""
jvm = getServerJvm(nodename,servername)
AdminConfig.modify(jvm, [[propertyname, value]])
But I'm met with this issue when i run the script
WASX7017E: Exception received while running file "/etc/was-scripts/administrateservertest.py"; exception information: com.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
File "", line 14, in ?
NameError: maximumHeapsize
Any suggestions would be appreciated as I'm tearing my hair out trying to work this out
this was answered by a friend on face book
I think you might need to make two calls, one for each property you
want to set. e.g.
setJvmProperty(nodeName,serverName,'maximumHeapsize',2048)
For others looking for a more specific answer, try this:
AdminConfig.modify(jvmId,[['genericJvmArguments',arguments],["maximumHeapSize", str(1536)]])