how to form address string to connect to solace using python - python-3.x

I want to consume messages from a already setup solace broker in my company. When i asked for the host name etc required to connect with solace, below details were provided by my company's solace team-
Connection factory - cf/dev_test_uk
VPN - dev_test_uk
VPN Server - smf://host:port
username - user1
password - password1
topic- testtopic
For reference I am using the code provide at https://github.com/SolaceSamples/solace-samples-amqp-qpid-proton-python
My code is -
from proton import Message
from proton.handlers import MessagingHandler
from proton.reactor import Container
class HelloWorld(MessagingHandler):
def __init__(self,url,address,username,password):
super(HelloWorld,self).__init__()
self.url = url
self.address = address
self.username = username
self.password = password
def on_start(self,even):
conn = event.container.connect(url = self.url,
user=self.username,
password=self.password)
event.container.create_receiver(conn, self.address)
def on_message(self, event):
print(event.message.body)
event.connection.close()
Container(HelloWorld("smf://host:port","topic://testtopic","user1","password1")).run()
when I run this code I get 'amqp:connection:framing-error',"SASL header mismatch:Insufficient data to determine protocol [''] (connection aborted)"
Which is expected as I don't think the url or address string formed is correct.
Following are the questions I have-
where should i use this VPN and connection factory while doing the connections?
VPN server url should't it be something like amqp://.... ?
Please help me with this.

Unfortunately....
Solace NO support python module to access Solace Protocol(SMF)....
you can OLNY wrap C API by yourself.....
because I am also need this Python Client API.....
so you can ref our project....
https://pypi.org/project/pysolace/
(WARRNING - unofficial)

Related

Gramex SMTP Email Issue

I have to send an email from python function to multiple users with dynamic content.
I have given email details in gramex.yaml as below
email:
barcode-mail-service:
type: gmail
email: gramex.guide#gmail.com
password: alphaBetaGamma
In my python function I have implemented mail functionality as below:
def email_users(_pending_users, approval):
mailer = service.email['barcode-mail-service']
content = []
if approval == 'Approved':
content = [f"Hi {obj['user']},\n\n \
Welcome to the Service online portal!"
for obj in
_pending_users.to_dict('r')
]
else:
content = [f"Hi {obj['user']},\n\n \
Your request has been rejected by the approver!"
for obj in _pending_users.to_dict('r')
]
to_list = _pending_users['email'].tolist() #gets list of all email ids
for index in range(len(to_list)): #loops over each mail id and sends the email
mailer.mail(
to=to_list[index],
subject=f'Barcode User Access {approval}',
html=content[index]
)
When I execute the above function I get the following error:
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
How can I fix this?
This seems to be a Firewall issue. SMTP internally uses port 25 for sending email. Enable (Allow) port 25 on your system and try if that works. You would need to enable this port on the server as well during deployment.
Note: Check which port is being used for sending the email by your Email Exchange
You can check this link to enable on Windows OS

How to control UserID in pymqi?

Got a trouble:
IBM MQ Server v9.1.0.0
pymqi==1.11.1
When trying connect to server got an error:
pymqi.MQMIError: MQI Error. Comp: 2, Reason 2035: FAILED: MQRC_NOT_AUTHORIZED
When I check traffic in Wireshark i got that:
And in server log this:
07/31/2020 10:08:02 AM - Process(27333.5) User(mqm) Program(amqrmppa)
Host(host) Installation(Installation1)
VRMF(9.1.0.0) QMgr(queue_manager)
Time(2020-07-31T07:08:02.253Z)
ArithInsert1(2) ArithInsert2(2035)
CommentInsert1(haha)
AMQ9557E: Queue Manager User ID initialization failed for 'haha'.
EXPLANATION:
The call to initialize the User ID 'haha' failed with CompCode 2 and Reason
2035. If an MQCSP block was used, the User ID in the MQCSP block was ''.
ACTION:
Correct the error and try again.
My code sample:
import pymqi
host = "host"
port = 1416
conn_info = f"{host}({port})"
channel = "channel"
queue_manager = "queue_manager"
def main():
manager = pymqi.connect(queue_manager=queue_manager, channel=channel, conn_info=conn_info)
if __name__ == '__main__':
main()
I tried to execute the code from other devices and there, accordingly, the account under which I ran was taken as the UserID.
After that I asked our support to deal with the problem, after which I was able to connect with an account haha, but the solution with the creation of a list of allowed users does not suit me. Is there any way to control the UserID that is sent by pymqi?
UPD 04.08.2020
The support team said that the user phoenix was created on the IBM MQ server with the password 123456789, tried to send an MQSCP:
manager = pymqi.connect(queue_manager=queue_manager, channel=channel,
conn_info=conn_info, user="phoenix", password="123456789")
And got similar error MQRC_NOT_AUTHORIZED and server log contains error as above with username of machine where code launches (not phoenix).

Not able to connect with my ftp server made using pyftpdlib in python

This is the code I have taken from the docs of pyftpdlib library. I get ftp locally but not able to access it from outside. I am using wifi from mobile and so I think I am behind NAT.
I have tried hours on getting this working but nothing worked.
Tried other similar question solutions but they had only some theory and that lead me to no result.
I need that I can connect with my ftp using my ip from outside network.
I have added firewall rules on port21 to allow all connections but it made no change. Also an explanation like which IP to be used when will be much helpful. Other related questions did no help to me.
import os
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
def main():
# Instantiate a dummy authorizer for managing 'virtual' users
authorizer = DummyAuthorizer()
# Define a new user having full r/w permissions and a read-only
# anonymous user
authorizer.add_user('user', '12345', '.', perm='elradfmwMT')
authorizer.add_anonymous(os.getcwd())
# Instantiate FTP handler class
handler = FTPHandler
handler.authorizer = authorizer
# Define a customized banner (string returned when client connects)
handler.banner = "pyftpdlib based ftpd ready."
# Specify a masquerade address and the range of ports to use for
# passive connections. Decomment in case you're behind a NAT.
handler.masquerade_address = 'My Public IP checked online'
handler.passive_ports = range(20, 65535)
# Instantiate FTP server class and listen on 0.0.0.0:2121
address = ('0.0.0.0', 21)
server = FTPServer(address, handler)
# set a limit for connections
server.max_cons = 256
server.max_cons_per_ip = 5
# start ftp server
server.serve_forever()
if __name__ == '__main__':
main()
Logs from cmd
In browser I connect by using ftp://X.X.X.X or ftp://localhost , here X.X.X.X is my prvate ip. Problem is how to make it available on my public ip so I can access from any device. On Public IP it gets timeout, I am on wifi.
[I 2020-05-11 20:27:13] concurrency model: async
[I 2020-05-11 20:27:13] masquerade (NAT) address: X.X.X.X
[I 2020-05-11 20:27:13] passive ports: 20->65534
[I 2020-05-11 20:27:13] >>> starting FTP server on 0.0.0.0:21, pid=9072 <<<
[I 2020-05-11 20:28:07] 127.0.0.1:5054-[] FTP session opened (connect)
[I 2020-05-11 20:28:07] 127.0.0.1:5054-[anonymous] USER 'anonymous' logged in.
[I 2020-05-11 20:28:07] 127.0.0.1:5054-[anonymous] CWD C:\Users\Dell\Desktop\ftp_server 250

Connection Refused Error When Trying to Connect to Outlook Using Python's poplib

I am trying to connect to Outlook using POP3 in python.
mailbox = poplib.POP3_SSL('outlook.office365.com', 995)
And I am getting the following error:
[WinError 10061] No connection could be made because the target machine actively refused it
I am using a VPN, and can ping 'outlook.office365.com' without issue. I also tried 'pop-mail.outlook.com' and 'pop3.live.com' as I saw them mentioned as hostnames online, and received the same error. Please let me know if there is any more useful information I can provide.
for the office 365 email settings it seems that the port for POP is 903. You can try using the settings in the web under Microsoft365 to also try fetching your email with IMAP.
Just to save you same time I wrote down some working lines using imap for fetching your emails and a simple code for sending using smtp
import smtplib
import imaplib
import ssl
def send_email():
send_port = 587
with smtplib.SMTP('smtp.office365.com', send_port) as smtp:
#Need a ehlo message before starttls
smtp.ehlo()
smtp.starttls()
# Server login
smtp.login(<user-email>, <password>)
# Email data
sender_email = <user-email>
receiver_email = <destination-email>
email_subject = <some-subjetct>
email_body = <some-body>
message = 'Subject: {}\n\n{}'.format(email_subject, email_body)
smtp.sendmail(sender_email, receiver_email, message)
smtp.quit()
def receive_email():
receive_port = 993
with imaplib.IMAP4_SSL('outlook.office365.com', receive_port) as imap:
# Server login
imap.login(<youremail>, <password>)
# Get the list of folders in you email account and some extra info.
retcode, folders = imap.list()
# status of the fetch
print ('Response code:', retcode)
# folders and info of hierarchies
print ('Response code:', folders)
imap.close()
#Test
send_email()
receive_email()
Be aware that this code needs the imap and smtp port open on your firewall.
Also use same user-email and password as you were using https://www.office.com/

Pull Syslog from the server using Groovy in Jira

I am new to Groovy in Jira, and I am trying to pull syslogs off a certain database. I am wondering if anyone can put me to the right direction. I am using the script console to implement this.
I am guessing it will be on the local host. I am given these to access the database server :
-Database server with Port Number
-Database name
-Password
-Application Database User
-Syslog Servers
Are there any tutorials I can use to be able to connect to the database server
Thank you very much,
Groovy provides the Sql class to simplify connecting to JDBC data sources. Here's an example.
import groovy.sql.Sql
def jdbc = 'jdbc:h2:mem:'
def db = Sql.newInstance(jdbc, 'org.h2.Driver')
def foos = db.rows('select foo from bar')
...
db.close() // Done with connection
The driver and JDBC connection string depends on the DBMS you're connecting to (MySQL, PostgreSQL, etc).
PostgreSQL example
Here's how to connect to PostgreSQL. The code below uses Groovy's Grape to download dependencies.
Note: #GrabConfig is required to load the org.postgresql.Driver class in a way that allows jdbc to find it.
#Grab('org.postgresql:postgresql:9.3-1101-jdbc41')
#GrabConfig(systemClassLoader=true)
import groovy.sql.Sql
def host = '192.168.1.1'
def port = 5432
def dbname = 'foo'
def user = 'xxx'
def password = 'yyy'
def jdbc = "jdbc:postgresql://${host}:${port}/${dbname}"
def db = Sql.newInstance(jdbc, user, password, 'org.postgresql.Driver')

Resources