My code:
import mido
import time
mido.set_backend('mido.backends.pygame')
output = mido.open_output()
output.send(mido.Message('note_on', note=64, velocity=60))
time.sleep(3)
output.close()
After the last line, the following error is printed:
Exception Exception: "PortMidi: `Bad pointer'" in <pypm.Output object at 0x025FF0B0> ignored
Apart from that, everything seems to work fine. However I'm developing a console app and this output is annoying. How can I get rid of this error?
I am using Windows 7 and Python 2.7.
You don't even have to set the RtMidi backend as it is the default, see mido backend documentation
Related
I have the following simple code:
import winrt.windows.applicationmodel.datatransfer as DataTransfer
clipboard = DataTransfer.Clipboard
print(clipboard.clear())
And am getting this error, any idea how to fix?
print(clipboard.clear())
RuntimeError: CoInitialize has not been called.
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.
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.
I'm currently trying to develop an application that uses the Modbus-RTU protocol, and I have to use modbus_tk in Python 2.7.
I'm supposed to use bits of code from another application which is able to communicate with the micro-controller via modbus. It works on that app when I run the following code, but I get an error when I run the same lines in my app.
import modbus_tk
import modbus_tk.defines as cst
import modbus_tk.modbus_rtu as modbus_rtu
import serial
MB_Add_Status = 8 + 5001
def MB_GetStatus(MB_Master_handle):
try:
status = MB_Master_handle.execute(1, cst.READ_HOLDING_REGISTERS, MB_Add_Status, 1)
return status
except modbus_tk.modbus.ModbusError, e:
logger.error("%s- Code=%d" % (e, e.get_exception_code()))
MB_port = 3
masterMB = modbus_rtu.RtuMaster(serial.Serial(port='COM'+str(MB_port), baudrate=19200, bytesize=8, parity='N', stopbits=2, xonxoff=0))
status = MB_GetStatus(masterMB)
First I needed to delete the arguments baudrate, bytesize, etc. in the constructor call because it rose an error like :
TypeError: __init__() got an unexpected keyword argument 'stopbits'
But then when we get to the call to execute, there is an error again, which I couldn't solve yet :
modbus_tk.modbus.ModbusInvalidResponseError: Response length is invalid 0
The only documentation I found is: https://github.com/Nobatek/modbus-tk/tree/master/docs, but I couldn't quite understand much of it. If someone could first explain me what this error really means, and where I should look, this would be highly appreciated. Thank you very much !
The right repository for this library is https://github.com/ljean/modbus-tk
It requires PySerial 2.7
Found it !
I updated the library and set the parameters of the constructor correctly. This works fine know.
When running OpenCV on Windows 7, using the standard python shell, I get the following behavior.
import cv
im = cv.LoadImageM("data/somefile.jpg")
thumb = cv.CreateMat(im.rows/6, im.cols/6, im.type)
print "Before"
cv.Resize(im, thumb)
print "After"
Gives:
>>> Before
========================= RESTART ==========================
No error is thrown, what should I look for? What causes such crashing in OpenCV/Python?
Most memory allocation in OpenCV is unchecked and can result in crashes. OpenCV also attempts to throw exceptions through C code, which may cause anything to happen (usually a crash) depending on how it was compiled.
Check whether the values of im.rows/6, etc. are what you expect and that the image sizes should be within python memory limits.
I had to rebuild OpenCV using Visual Studio (Express) 2010, in stead of MinGW, that did the trick, so I guess it was just a faulty build in the end.
i don't think your program is crashing,it is doing just what you are telling it to do.
See the codes below,am using openCv 2.2 with python 2.7.2.Try using WaitKey() to prevent crashes!
import cv
cv.NamedWindow("win",cv.CV_WINDOW_AUTOSIZE)
im= cv.LoadImageM("image.jpg")
thumb= cv.CreateMat(im.rows/3, im.cols/3, im.type)
cv.Resize(im, thumb)
cv.ShowImage("win",thumb)
cv.WaitKey(10000)