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!
Related
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()
I'm trying to write a script to test all DataSources of a WebSphere Cell/Node/Cluster. While this is possible from the Admin Console a script is better for certain audiences.
So I found the following article from IBM https://www.ibm.com/support/knowledgecenter/en/SSAW57_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/txml_testconnection.html which looks promising as it describles exactly what I need.
After having a basic script like:
ds_ids = AdminConfig.list("DataSource").splitlines()
for ds_id in ds_ids:
AdminControl.testConnection(ds_id)
I experienced some undocumented behavior. Contrary to the article above the testConnection function does not always return a String, but may also throw a exception.
So I simply use a try-catch block:
try:
AdminControl.testConnection(ds_id)
except: # it actually is a com.ibm.ws.scripting.ScriptingException
exc_type, exc_value, exc_traceback = sys.exc_info()
now when I print the exc_value this is what one gets:
com.ibm.ws.scripting.ScriptingException: com.ibm.websphere.management.exception.AdminException: javax.management.MBeanException: Exception thrown in RequiredModelMBean while trying to invoke operation testConnection
Now this error message is always the same no matter what's wrong. I tested authentication errors, missing WebSphere Variables and missing driver classes.
While the Admin Console prints reasonable messages, the script keeps printing the same meaningless message.
The very weird thing is, as long as I don't catch the exception and the script just exits by error, a descriptive error message is shown.
Accessing the Java-Exceptions cause exc_value.getCause() gives None.
I've also had a look at the DataSource MBeans, but as they only exist if the servers are started, I quickly gave up on them.
I hope someone knows how to access the error messages I see when not catching the Exception.
thanks in advance
After all the research and testing AdminControl seems to be nothing more than a convinience facade to some of the commonly used MBeans.
So I tried issuing the Test Connection Service (like in the java example here https://www.ibm.com/support/knowledgecenter/en/SSEQTP_8.5.5/com.ibm.websphere.base.doc/ae/cdat_testcon.html
) directly:
ds_id = AdminConfig.list("DataSource").splitlines()[0]
# other queries may be 'process=server1' or 'process=dmgr'
ds_cfg_helpers = __wat.AdminControl.queryNames("WebSphere:process=nodeagent,type=DataSourceCfgHelper,*").splitlines()
try:
# invoke MBean method directly
warning_cnt = __wat.AdminControl.invoke(ds_cfg_helpers[0], "testConnection", ds_id)
if warning_cnt == "0":
print = "success"
else:
print "%s warning(s)" % warning_cnt
except ScriptingException as exc:
# get to the root of all evil ignoring exception wrappers
exc_cause = exc
while exc_cause.getCause():
exc_cause = exc_cause.getCause()
print exc_cause
This works the way I hoped for. The downside is that the code gets much more complicated if one needs to test DataSources that are defined on all kinds of scopes (Cell/Node/Cluster/Server/Application).
I don't need this so I left it out, but I still hope the example is useful to others too.
Are there any examples on the net how to process errors when downloading data from Interactive Brokers using the IBrokers package? I've had a look at the package details and eWrapper and twsCALLBACK seem to handle this but I can't get them to work. For example the code below produces an error and R hangs, the error msg isn't processed. Thanks for any suggestions.
contract <- twsContract(0,
symbol="SPI",
sectype="XXX", #bad sectype
exch="SNFE",
primary="",
expiry= "20181220",
strike="",
currency="AUD",
right="",
local="",
multiplier = "25",
combo_legs_desc = "",
comboleg = "",
include_expired = "",
secIdType = "",
secId = "")
tws <- twsConnect()
data <- reqMktData(tws,contract,snapshot = TRUE)
You should append a "Disconnect" command to you code. Otherwise your program try to build to connections on the same port, that's not possible and it will not terminate.
I don't know the IBroker package very well, please check the command for disconnecting and append it to your code. Refresh your command line and rerun your code.
In addition, connect to IB Gateway instead of TWS by using that port number (check API settings of your IB Gateway application). In the settings choose a detailed Log.
Run your code again (after changing port number) and send your log file. Then I will try to help more. It's hard to help without any error message.
Just encountered a similar issue as described in the below article:
Question: Article with similar error description
java.rmi.UnmarshalException: cannot unmarshaling return; nested exception is:
java.rmi.UnexpectedException: Failed to parse descriptor file; nested exception is:
java.rmi.server.ExportException: Failed to export class
I found that the issue described is totally unrelated to any Java update and is rather an issue with the Weblogic bean-cache. It seems to use old compiled versions of classes when updating a deployment. I was hunting a similar issue in a related question (Question: Interface-Implementation-mismatch).
How can I fix this properly to allow proper automatic deployment (with WLST)?
After some feedback from the Oracle community it now works like this:
1) Shutdown the remote Managed Server
2) Delete directory "domains/#MyDomain#/servers/#MyManagedServer#/cache/EJBCompilerCache"
3) Redeploy EAR/application
In WLST (which one would need to automate this) this is quite tricky:
import shutil
servers=cmo.getServers()
domainPath = get('RootDirectory')
for thisServer in servers:
pathToManagedServer = domainPath + "\\servers\\" + thisServer.getName()
print ">Found managed server:" + pathToManagedServer
pathToCacheDir = pathToManagedServer + "\\" + "cache\\EJBCompilerCache"
if(os.path.exists(pathToCacheDir) and os.path.isdir(pathToCacheDir) ):
print ">Found a cache directory that will be deleted:" + pathToCacheDir
# shutil.rmtree(pathToCacheDir)
Note: Be careful when testing this, the path that is returned by "pathToCacheDir" depends on the MBean-context that is currently set. See samples for WLST command "cd()". You should first test the path output with "print domainPath" and later add the "rmtree" python command! (I uncommented the delete command in my sample, so that nobody accidentially deletes an entire domain!)
I had this error pop up on exactly the 3rd line of code below. There seem to be no explanation on the Internet for this behaviour.
I'm looking at why this error came up, and fixed itself after few minutes.
Set Ftp = CreateObject("Reflection.FTP.3")
Ftp.Open "xxx.xxx.xxx.xxx", "username", "password"
Ftp.SetCurrentDirectory "DirectoryName/DirectoryName/DirectoryName"
What was the error?
Run-time error '-2147418113 (8000ffff)':
Method 'SetCurrentDirectory' of object 'IReflectionFTP' failed
More details:
Application: Excel Macro
Language : VB (VBA)
*Is this because of a coding error? *
Not likely. The macro has been long running and this came up for the first time.
*Is it because of a FTP service disruption? *
May be. But logs have a recording for every second and there seems to be no outage.
It seems to me there is a connection problem here - maybe a timeout? I assume that your three lines of code don't execute one after another (ie the SetCurrentDirectory is after some more code). This error will come up if the Ftp object doesn't have a valid connection that is logged in. Change the IP for the Open command to an invalid one and you'll see you get the same error.
Try setting the following line of code before SetCurrentDirectory command.
If FTP.Status = rcLoggedIn + rcConnected Then
Ftp.SetCurrentDirectory "DirectoryName/DirectoryName/DirectoryName"
Else
'Error handle
End If
Note, that you are late binding the object so for it to work for you, you'll need the If statement to be:
If FTP.Status = 17 Then
Also, if it is a timeout problem then I'd set the Timeout period for the session to be longer, ie FTP.TimeoutSession = 300.