Hi there I am having issues with Quick Fix python. I need to add Tag 554 to my outbound Logon message to send messages in to the exchange as it is required but I am unsure how to go about this. All the online examples I find are C++ code and my attempts to translate those to Python are not successful.
If someone could advise how to send Logon messages out with a password tag it would be appreciated:
def toAdmin(self, sessionID, message):
message.getHeader().setField(554, "password")
Your code looks close to correct. You didn't actually say what happens you run it, so I can't be 100% sure what you think is wrong with it.
But there is one improvement that is needed: You only want to set the password on Logon messages.
def toAdmin(self, sessionID, message):
if message.getHeader().getField(35) == "A":
message.getHeader().setField(554, "password")
(Forgive any Python syntax errors; it's not a language I know well.)
This is very similar to what you'd do in any other QF port. For instance, see the QuickFIX/n User FAQ for the C# way.
Related
Over the summer, I was successfully using the PyTextNow python library to send text messages from my raspberry pi to my phone with python. I stopped using it for a while, around a month. When I tried to use it again, my phone number on TextNow had expired and I was given new one. Since then, I have been unable to use my previous code even though I made all the needed adjustments for the new phone number. I get error that looks like this: FailedRequest: Could not send message. server return a Server error. Request Failed. Status Code: 520
Here is my code
import pytextnow as pytn
client = pytn.Client(#username#, #connect.sid#)
client.send_sms("phone #", "Hello")
I have verified that the username, connect.sid cookie, and phone number are all correct numerous times. I also set up a second TextNow account, modifying the code with the new username and connect.sid values, and got the same error. I know that I am connecting to the correct account because the client.get_unread_messages() function will pull up the correct messages. To my knowledge, it is only the send message function that is not working. Any help that would enable me to send sms messages again with PyTextNow, or a better way to send and read messages in python, would be appreciated. Thanks!
I know that python compatibility with gmail changes all the time when google does things that make it harder for other 'apps' to access the email. For the purposes of this code I have created a brand new account with Less secure app access enabled. There is no 2 step verification on this account, so naturally there is no app-specific password functionality, and the email password I use should be my email's actual password (at least I think?).
Sidenote I have also taken these steps to remove security from my account
I was following instructions from a fairly recent guide on using python to send gmail https://pybit.es/python-smtplib.html
with the following example code provided:
import smtplib
smtp_server = smtplib.SMTP('smtp.gmail.com', 587)
smtp_server.ehlo()
smtp_server.starttls()
smtp_server.login('pybitesblog#gmail.com', '<App Password>')
smtp_server.sendmail('pybitesblog#gmail.com', 'recipient#gmail.com', 'Subject: Happy Australia Day!\nHi Everyone! Happy Australia Day! Cheers, Julian')
smtp_server.quit()
print('Email sent successfully')
Whenever I run the exact code wiith the expected things replaced, my code ends up hanging and the email never gets sent. Does anyone know as of right now, what code will work?
Alright for whatever reason 10 minutes later the emails show up in my sent mail box despite me terminating both times and the emails were successfully delivered, just into my spam folder. I am still unable to reproduce this, and I don't know exactly what code sent those emails. It had to be some form of the code I posted above, however, because the emails I got had that specific message that other websites with alternative methods obviously weren't using.
I decided to write a websocket chat that he supported text messaging [unlimited number of characters, not like Twitter :)] and file transfer.
Ask this question. How to make banal identification data? That is, when the connection is open, the server is just a set of bytes, and even if there is json, it can be easy to substitute: mark as "message" and send confusing file(since the number of characters is not limited, it will sent to all people users).
That is, briefly, how to discern what comes from the user?
Thanks in advance!
P.S. Transfer files via jquery is not accepted, as the websocket is not protected.
UPD
Any wrote that did not understand a question essence. Explain: 1. There is a chat on tornado WS. 2. In chat can send as text messages and files. 3. I control it with javascript BUT if someone will make a connection and send a file for example, as a message? Clients receives a huge number of "unknown byte". The situation is like this - {'msg': 'Hello, world!!1'}; {'file': a file}. All is well, but it would be a shame if {'msg': a file}. It should be clear ;)
Welcome to SO.
Before I answer your question, allow me to clarify a few points about this site and our community. This is your first question, so maybe you didn't know:
SO (StackOverflow) is not a forum, it's more like both a chat and a library. If you ask a question, you are expected to stay on line for at least an hour or two to check in and give more information if somebody asks you.
If somebody asks for more information, edit the question - don't answer inside the comments (you can add a comment saying that you updated the question, but the question should be edited).
If you are not here to clarify your question, it WILL be closed because there are many people wanting answers and we give priority to the people who are here to respond.
It is important that your questions include information about what you already tried. It is better if your questions include some of the code you wrote when you tried your own solution.
Otherwise, it feels like you are trying to outsource your work to the community - which is a very big No No.
It is important that your questions are clear and that you write in the best English that you can manage.
Please read the comments to see what I mean about the community's expectations.
As for Websocket security:
I do not know what language you work with, so I will write in Ruby because it's easier for me and I think the code will be easier to read.
Websockets start as an HTTP connection which is then "upgraded" to a websocket connection.
Since most applications already have HTTP security / authentication logic that they wrote for the website, it is best to use this same security / authentication logic for websockets.
This is usually done BEFORE the connection is upgraded.
It is true that sometimes people write a new security / authentication logic layer for websockets, but that is not the most effective way to deal with this issue (mainly because messages could be sent to the websocket while authentication is still being processed, which starts a new world of issues and considerations).
Here is an example, using the Plezi framework, that requires authentication before the upgrade. test this example by installing the plezi gem (terminal: $ [sudo] gem install plezi) and running the following code in irb (terminal : $ irb):
require 'plezi'
class WebsocketSecDemo
# pre_connect is called before the upgrade, while still in HTTP mode.
def pre_connect
# return false (refuse the connection) unless the auth logic is okay
return false unless auth_logic
true
end
def on_message data
puts "got #{data}"
response << data
broadcast :ws_write, data
end
def index
"Check this using http://www.websocket.org/echo.html
\r\nConnect to the websocket at ws://localhost:3000/
\r\nTo authenticate, visit http://localhost:3000/login
\r\nTo un-authenticate visit http://localhost:3000/logout"
end
def login
cookies[:my_auth] = true
redirect_to :index
end
def logout
cookies[:my_auth] = nil
redirect_to :index
end
# protected methods aren't available to the HTTP router.
protected
def ws_write data
response << data
end
# The worst auth logic in the history of man kind...
def auth_logic
cookies[:my_auth] == true
end
end
Plezi.listen
Plezi.route '/', WebsocketSecDemo
# exit the terminal to start the demo
exit
Now visit:
localhost:3000 - for instructions
localhost:3000/login - to authenticate
localhost:3000/logout - to remove authentication
Also use www.websocket.org/echo.html a few times to try and connect to the websocket at ws://localhost:3000/ - try this:
before authentication;
after authentication (login); and
after you 'logout'...
Good Luck!
I'm trying out GAE and having a little trouble sending email from my application in both development and production. I understand the development server needs a little configuration first, but production should be send email. There are no errors that I can see viewing the console (I start the server via terminal window), and none reported in the production application.
The code:
def contactSend():
message = mail.EmailMessage()
message.sender = "myaddress#gmail.com"
message.to = "myaddress#gmail.com"
message.subject = "Test email from python"
message.body = "This is the test"
message.send()
What I have checked so far:
Code appears to be correct.
-Sender (and to) address have administrator level permissions of the project.
-Project is configured as Python 2.7 (some issues on 2.5 I guess).
-My spam folder.
I'm sure I'm likely missing something simple as I'm very new to GAE. Any ideas would be greatly appreciated.
Edit: I've also tried mail.sendmail:
mail.send_mail(sender="myaddress#gmail.com",
to="myaddress#gmail.com",
subject="This is the test 1124pm",
body="TEST!")
No luck there either. Possible that I need to register a domain or set up a Google Apps account maybe?
Edit2 11:52am: I've tried a check_valid_email to be sure and that came back true. I saw the "send_mail_to_admins" function and gave that a shot assuming it might be less restricting and possibly work, but nothing there either.
Edit3: I don't know if it helps but here's the request handler:
class contactSend(webapp2.RequestHandler):
def post(self):
self.response.headers['Content-Type'] = 'text/html'
contactSend()
self.response.out.write("sent! ")
Your code snippets appear to be correct (with the exception of improper indentation of your first function), so I'm going to provide some debugging information to help you solve your problem.
Check the Logs of your application to see if any exceptions are being raised by your code which may prevent things from working as intended.
https://appengine.google.com/logs?&app_id=YOUR_APP_ID
Check the Quota Details of your application to see if any emails have been sent.
https://appengine.google.com/dashboard/quotadetails?&app_id=YOUR_APP_ID
Ensure the sender email address has accepted the App Engine invite and is not listed as "pending" on the Permissions page.
https://appengine.google.com/permissions?&app_id=YOUR_APP_ID
Double-check the to and sender email addresses. Copy/paste them and try to send an email to them directly through the email application of your choice.
In order to be able to send e-mails from a certain address, you need to set up a domain first, and grant access to the application to send e-mails using it.
If you don’t want/need to set up a domain, and if you application requires log in, you could simply use:
mail.send_mail(sender=users.get_current_user().email(),
to="myaddress#gmail.com",
subject="This is the test 1124pm",
body="TEST!")
QuickFIX logon trouble: (using QuickFIX, with FIX 4.4 in Python 2.7)
Once I do initiator.start() a connection is made, and logon message is sent. However, I don't ever see the ACK and session status message that the broker is sending back (all the overloaded Application methods are just supposed to print out what they receive).
QuickFIX immediately re-tries the logon (according to the broker log files), and the same thing happens, but according to the server, I am already logged in.
QuickFIX then issues a Logout command, which the server complies with.
I have tried enter Timeout values in the settings file, but to no avail. (Do I need to explicitly reference these values in the code to have the utilized, or will the engine see them and act accordingly automatically?)
Any ideas what is going on here?
Sounds like you do not have message logs enabled. If your app rejects messages below the application level (such as if the seq no is wrong, or the message is malformed), then it'll be rejected before your custom message handlers even see it.
If you are starting your Initiator with a ScreenLogStore, change it to a FileLogStore. This will create a log file that will contain every message sent and received on the session, valid or not. Dollars to donuts you'll see your Logon acks in there as well as some Transport-layer rejections.
Solved! I think there was something wrong with my datadictionary (FIX44.xml) file. I had seen a problem in it before, but thought I fixed it. I got a new copy online and dropped it in and now everything seems to be working. Maybe the bad dictionary was not letting FIX accept the logon response?