Added more parameters to smtplib.SMTP in python - python

Im trying to make a script that sent an email with python using smtp.smtplib , almost of examples i found while googling shows how to call this function with only smtpserver and port parameters.
i want to added other paramaters : domain and binding IP
i tried this : server = smtplib.SMTP(smtpserver, 25,'mydomain.com',5,'myServerIP')
I got this as error : TypeError: init() takes at most 5 arguments (6 given)
Can you suggest a way to do this?

This error is likely because the parameters are invalid (there is one too many). Try looking at the smtplib docs to see what parameters are valid

Related

Python OPC UA call method without arguments gives error

I am trying to call a method with no input arguements which is as follows :
[1]
[1]: https://i.stack.imgur.com/tGFe9.png
So far I have tried this :
method=client.get_node("ns=5;s=Demo.StateMachines.Program01.Reset")
parent=client.get_node("ns=5;s=Demo.StateMachines.Program01")
output=parent.call_method(method)
but it given me this BadNotExecutable error:
"The executable attribute does not allow the execution of the method."(BadNotExecutable)
The server is telling you this method cannot be executed.
There doesn't appear to be anything wrong with your client, check the server configuration.

camera.set_controls() not working on RasPI

Is it possible that Camera.set_controls() doesn't work in pygame?
I am on Version 1.9.x and try it on my RasPi, but it always crashes.
It says there are no keyword arguments - But if I don't use keywords, it crashes with another message (I don't have the message in my mind at moment)
Errors:
This was sent via PuTTy, but it doesn't work if I directly use it on the RasPi, too.
The error message is see unambiguously:
set_controls() takes no keyword argument
So you can't write camera.set_controls(hflip = True, vflip = True), but you have to write
camera.set_controls(True, True)
Note set_controls is implmented using CPython. Also see GitHub - Pygame - _camera.c

Syntax error with Cloud 9?

I'm new to Cloud 9, and have made a script. I want the code to appear at the url https://python-william1835.c9.io and I receive the following message:
Important: use os.getenv(PORT, 8080) as the port and os.getenv(IP,0.0.0.0) as the host in your scripts!
when I run it.
So I put it in the script (along with import os of course). And when I run it again, it says:
File "/home/ubuntu/workspace/Python Projects/Python Enigma Program/main.py", line 14
os.getenv(IP, 0.0.0.0)
^
SyntaxError: invalid syntax
Can you tell me why it does this?
You get a SyntaxError because the literal 0.0.0.0 is syntactically invalid.
The message you're receiving is a bit misleading in this specific case. Additionally, the documentation page for os.getenv is unfortunately not as verbose as one would want.
But, if you look at the source code for getenv you'll see that all arguments must be of type str:
def getenv(key, default=None):
"""Get an environment variable, return None if it doesn't exist.
The optional second argument can specify an alternate default.
key, default and the result are str."""
return environ.get(key, default)
Changing your calls to:
os.getenv("PORT", "8080")
os.getenv("IP", "0.0.0.0")
Should work and you should have no problem using them.

how to call function in paramiko

for transfer entire folder to server using sftp with paramiko. I copy this code from stackoverflow
but my doubt is how to call that function, I put like this ..
sftp = paramiko.SFTPClient.from_transport(t)
M = MySFTPClient()
M.put_dir()
M.mkdir()
but Its throwing this error:
*** Caught exception: <type 'exceptions.TypeError'>: __init__() takes exactly 2 arguments (1 given)
The error message indicates that the function you are calling takes two arguments while you are sending zero. Try doing something like this instead:
t = paramiko.Transport(("ftpexample.com", 22))
t.connect(username = myusername, password = mypassword)
sftp = paramiko.SFTPClient.from_transport(t)
Use the sftp client to upload your file at localpath (e.g. /usr/tmp/test.png") to your remote path:
sftp.put("localpath","remotepath")
I haven't used Paramiko, but reading the source code it seems that you can already use the sftp object returned from the from_transport method. So no need to create another MySFTPClient()
In a Python console try reading help(paramiko.SFTPClient) and help(paramiko.SFTPClient.from_transport). Also browsing sftp.py seems helpful as the list of available commands is in the beginning (put_dir does not seem to be one of them).

Webbrowser TypeError in Python

I am trying to use webbrowser.open to send an email using the default mail client. My code looks like this:
mailto = "mailto:me#bla.com?subject=blabla&body=blabla"
webbrowser.open(mailto)
Although the mail client (Outlook) opens normally, I keep getting the following TypeError:
TypeError: open() takes at least 1 argument (0 given)
I tried to use something like webbrowser.open(mailto,1) but the result is still the same.
Why could this happen?
Its not the webbrowser.open, mailto is 1 argument no matter what value it is. So you need to check again where the troublesome open invoking belongs to.

Categories

Resources