Webbrowser TypeError in Python - 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.

Related

How to pass multiple arguments to a function from module instead of command line?

I am using this script: https://developers.google.com/youtube/v3/docs/videos/insert
And I can run it from command line without problem like this (for example):
python3 upload_youtube.py --file file_to_upload.mp4
I want to call this module from another, so I write this simple script:
import upload_youtube
upload_youtube.initialize_upload(['youtube', 'options'])
But when I execute it I get this error:
TypeError: initialize_upload() missing 1 required positional argument: 'options'
I try using the argument directly in the call, like this:
upload_youtube.initialize_upload(['youtube', "--file 'video.mp4'"])
But it doens works... I get the same error, so I I doing some wrong, but I don't know what is it.
I appreciate your help.
Thank you.
Since we don't know what upload_youtube.py or the methods within are (I didn't see that module anywhere in the link you included), we can only guess.
As such, my guess is that the method you're calling is expecting arguments as separate items, not a list, which is why you're missing an argument. As such, try:
upload_youtube.initialize_upload("youtube", "options")
and see where that gets you.

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.

Added more parameters to smtplib.SMTP in 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

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).

Categories

Resources