Metatrader5 - Python Integration - symbol_total() returns None - python

I'm trying to get the number of symbols of metatrader5 and I'm getting an error
TypeError: '>' not supported between instances of 'NoneType' and 'int'
Link to the documentation: https://www.mql5.com/en/docs/integration/python_metatrader5/mt5symbolstotal_py
code:
import MetaTrader5 as mt5
print("MetaTrader5 package author: ",mt5.__author__)
print("MetaTrader5 package version: ",mt5.__version__)
if not mt5.initialize():
print("initialize() failed, error code =",mt5.last_error())
quit()
symbols=mt5.symbols_total()
if symbols>0:
print("Total symbols =",symbols)
else:
print("symbols not found")
mt5.shutdown()
The problem is that the function is returning NoneType instead of a number.
Why it's returning a NoneType? How can i get the list of Symbols/Stocks?
Any clue?

I had the same problem too. If you are currently using a downloaded MT5 terminal from your broker, you can try using the official MT5 terminal instead. That seemed to have fixed my issue. Don't forget to specify the path to the correct MT5 terminal.exe afterwards within the initialization function initialize(path=...).
As to why this was causing an issue, I'm unsure myself. I happened across this post and it mentioned that there may have been modifications made by brokers.
Anyway, hope this works for you too!
To connect to your broker's server afterwards, within the MT5 terminal under Navigator->Accounts (Right Click)->Open an account->Search for your broker and enter your credentials.

Related

kubeflow AttributeError: 'ComponentStore' object has no attribute 'uri_search_template'

I am trying to load some prebuit gcp kubeflow components using kfp.components.ComponentStore. However I am getting this error:
line 180, in _load_component_spec_in_component_ref
if self.uri_search_template:
AttributeError: 'ComponentStore' object has no attribute 'uri_search_template'
when at this line of code:
mlengine_train_op = component_store.load_component('ml_engine/train')
KFP version:
kfp 1.8.10
kfp-pipeline-spec 0.1.13
kfp-server-api 1.7.1
Steps to reproduce
import kfp
from kfp.components import func_to_container_op
COMPONENT_URL_SEARCH_PREFIX = "https://raw.githubusercontent.com/kubeflow/pipelines/1.7.1/components/gcp/"
component_store = kfp.components.ComponentStore(
local_search_paths=None, url_search_prefixes=[COMPONENT_URL_SEARCH_PREFIX])
mlengine_train_op = component_store.load_component('ml_engine/train')
mlengine_deploy_op = component_store.load_component('ml_engine/deploy')
I got this code from an example that was running on kfp 0.2.5. This is probably some version problem but does anyone knows how to update this code to the newer version?
I solved the issue. It is something that #Kabilan Mohanraj also mentioned is his comment. It looks like there is a bug if you don't set up uri_search_template when creating the ComponentStore.
I solved it by providing it as parameter, it doesn't really matter what you pass to the constructor really, but it is required because in the code there is the following
if self.url_search_prefixes:
but if you don't pass something that attribute doesn't get created in the constructor.
I fixed it like this:
component_store = kfp.components.ComponentStore(
local_search_paths=["local_search_path"], url_search_prefixes=[COMPONENT_URL_SEARCH_PREFIX]), uri_search_template="{name}/"
I hope it will help someone in the future.
I suggested in the github issue to address this by either make the error more clear or to have better check on uri_search_template attribute.

059 Python: Tensorflow - AttributeError: 'OwnedIterator' object has no attribute 'string_handle'

the code is as follows :
iterator = tf.compat.v1.data.make_one_shot_iterator(batched_dataset)
handle = iterator.string_handle()
i try to run a Captcha crack code which is this github project and despite the fact that i had to modify so many parts of the code for compatibility issues i face this error and the error says :
AttributeError: 'OwnedIterator' object has no attribute 'string_handle'
i have been trying for more than 1 day and couldn't and can't find any solution to this issue hope someone help me run the code with No Error!
i am using Pycharm and python and Tensorflow version = 2.4.1

"504 Gateway Timeout" while executing python cgi script

The following example code:
#!/usr/bin/python3
from astropy.time import Time
from astropy.coordinates import solar_system_ephemeris, EarthLocation, get_body
print('Content-Type:text/html;charset=utf-8\n')
t = Time("2014-09-22 23:22")
loc = EarthLocation.of_site('greenwich')
with solar_system_ephemeris.set('builtin'):
jup = get_body('jupiter', t, loc)
print('<h2>',jup.ra.deg,'</h2>')
works OK when the script runs locally (=136.9111620895066). But if I try to execute it from the server a "504 Gateway Time-out" Nginx error appears.
Maybe something is wrong with the file where astropy holds the ephemerides data? Other astropy, matplotlib, etc. scripts work fine from the server. The error appears every time the script needs ephemerides flles (jpl, esa ...).
Make sure you have the latest bugfix release of astropy (v3.2.3, http://docs.astropy.org/en/latest/changelog.html#id153) since it fixes an issue with IERS URLs, which is likely the cause of you "504 Gateway Time-out" error.

ReceivedTime of the mail is not showing in python

I am trying to read my mail and see the received time in outlook 2016 using MAPI.
I am able to see the subject of the mail not able to see the receivedTime of the mail. I know that "Receivedtime" is there to get the received time of the mail, but while the program is executed,
a popup is coming, telling that python has stopped working
I know it is not due to any machine problem rather some problem in my code.
Here is my code.
def arrange(mailbox):
global spam
timeperiod() # stores required date in spam[] list
msgs=mailbox.Items
msgs.Sort("[ReceivedTime]", True)
p=msgs.restrict(" [ReceivedTime] >= '"+spam[2]+"'") #and [ReceivedTime] >= '" +spam[1]+"'
print(len(p))
'''
for m in list1:
if m.Unread:
m.Unread=False
'''
return p
#Calling it
ctm1=arrange(ctm)
print(len(ctm1)) #Working fine
for message in ctm1:
print (message.subject) #Also works good
print (message.receivedTime) # Here is the problem, it's not showing
]1
i have tried Senton property as well, but it's not working . So any guesses why the senton or receivedTime properties are not working???
updated code :
def printlist(box1) :
print(len(box1))
for message in box1:
if message.Class==43 :
# print('true')
print (message)
#.senderEmailAddress) #working
#print(message.SentOn.strftime("%d-%m-%y")) #not working
#print(message.body)
#print(message.UnRead)
#print (message.receivedTime) #not working
#print('-----------')
I was also having trouble with the .ReceivedTime breaking the program when I compile the .py script to an .exe using auto-py-to-exe.
Here's where the error occurs underneath this try: statement
try:
received_year = str(email.ReceivedTime)[0:4]
received_month = str(email.ReceivedTime)[5:7]
received_day = str(email.ReceivedTime)[8:10]
This works PERFECTLY well inside of my IDE (PyCharm), but once I've compiled it to .exe, it breaks here.
I've updated pywin32 to the most up-to-date version (228) and also tried using 224 to see if it was a version issue (it wasn't).
BUT!! Going through this, I FOUND THE BUG! When you compile to .exe with auto-py-to-exe, it does not include the package "win32timezone" which the .ReceivedTime portion needs to run correctly. So you need to import this package for it to work.
All you have to do to fix this is include this at the top of your .py script before compiling to .exe:
import win32timezone
Let me know if this works for anyone else facing this issue!
Most likely you run into an item other than MailItem - you can also have ReportItem and MeetingItem objects in your Inbox; none of them expose the ReceivedTime property.
Check that message.Class property == 43 (olMail) before accessing any other MailItem specific properties.
Please try the below:
print([x.ReceivedTime for x in messages])

Gurobi Python Error (NoneType has no len())

I need to write an optimization file for Gurobi (Python) that is a modified version of a classic TSP. I tried to run the example file from their website:
examples.gurobi.com/traveling-salesman-problem/
I always get the following error:
TypeError: object of type 'NoneType' has no len()
What do I need to change?
Thx
Full code: https://www.dropbox.com/s/ewisx805b3o2wq5/beispiel_opt.py?dl=0
I can confirm the error with the example code from Gurobi's website. At the first look the problem seems to be inside the subtour function, that returns None if sum(lengths) == n and the missing check for if tour is None inside the subtourlim function.
Instead of providing a fix for the specific code, I first checked the examples that Gurobi installs inside the specific installation directory:
Mac: /Library/gurobi810/mac64/examples/python/
Linux: /opt/gurobi800/linux64/examples/python/
Windows: c:\gurobi800\win64\examples\python\
And surprisingly the tsp.py from there runs without any errors. Note also that the two mentioned functions are revised. So I guess the example from the website is just a old version of the code.

Categories