When I try to user the command db.create_all() to build my sqlalchemy database (with flask-sqlalchemy) for my flask application I get an issue, and I can not fix this, this is the error code:
File "c:\users\paulo\desktop\python\projects\paper_note\venv\lib\site-packages\pymysql\connections.py", line 614, in connect
(self.host, self.port), self.connect_timeout, **kwargs
File "C:\Program Files\Python37\lib\socket.py", line 707, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "C:\Program Files\Python37\lib\socket.py", line 752, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed
During handling of the above exception, another exception occurred:
File "c:\users\paulo\desktop\python\projects\paper_note\venv\lib\site-packages\sqlalchemy\engine\default.py", line 509, in connect
return self.dbapi.connect(*cargs, **cparams)
File "c:\users\paulo\desktop\python\projects\paper_note\venv\lib\site-packages\pymysql\connections.py", line 353, in __init__
self.connect()
File "c:\users\paulo\desktop\python\projects\paper_note\venv\lib\site-packages\pymysql\connections.py", line 664, in connect
raise exc
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'dbserver' ([Errno 11001] getaddrinfo failed)")
I hope this will help other people, to fix this error I verified my database connection URL, and that was incorrect.
Related
I'm trying to connect to database of https://www.freesqldatabase.com but it's not connecting through given code.
But as I connect to my database through phpmyadmin it connects.
import mysql.connector
cnx = mysql.connector.connect(user='user', password='pass',
host='host',
database='database',
port='3306')
try:
cursor = cnx.cursor()
cursor.execute("""
select * FROM USERS
""")
result = cursor.fetchall()
print(result)
finally:
cnx.close()
Everytime I run this code I get these errors.
Traceback (most recent call last):
File "C:\Users\kanwa\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mysql\connector\network.py", line 482, in open_connection
addrinfos = socket.getaddrinfo(self.server_host,
File "C:\Users\kanwa\AppData\Local\Programs\Python\Python38-32\lib\socket.py", line 918, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "as.py", line 2, in <module>
cnx = mysql.connector.connect(user='user', password='pass',
File "C:\Users\kanwa\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mysql\connector\__init__.py", line 179, in connect
return MySQLConnection(*args, **kwargs)
File "C:\Users\kanwa\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mysql\connector\connection.py", line 95, in __init__
self.connect(**kwargs)
File "C:\Users\kanwa\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mysql\connector\abstracts.py", line 716, in connect
self._open_connection()
File "C:\Users\kanwa\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mysql\connector\connection.py", line 206, in _open_connection
self._socket.open_connection()
File "C:\Users\kanwa\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mysql\connector\network.py", line 500, in open_connection
raise errors.InterfaceError(
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on 'host:3306' (11001 getaddrinfo failed)
import smtplib
def sendEmail(receiver,subject,message):
server = smtplib.SMTP('smtp.gamil.com',587)
server.ehlo()
server.starttls()
server.login("botsinhala#gmail.com",password)
server.sendmail("botsinhala#gmail.com",receiver,message)
print("succesful")
sendEmail("gadjetrathnayake#gmail.com","testing bot","Hi, This is a testing message i'm sending to you.")
above code is generating the following error. My OS is windows 10.
Traceback (most recent call last):
File "D:/MY CHANNEL/python tricks/Email bot 1/tttttttttttttttttttttttt.py", line 17, in <module>
sendEmail("andrewhawkins#gmail.com","testing bot","Hi, This is a testing message i'm sending to you.")
File "D:/MY CHANNEL/python tricks/Email bot 1/tttttttttttttttttttttttt.py", line 5, in sendEmail
server = smtplib.SMTP('smtp.gamil.com',587)
File "C:\Users\Dell Pc\AppData\Local\Programs\Python\Python37-32\lib\smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "C:\Users\Dell Pc\AppData\Local\Programs\Python\Python37-32\lib\smtplib.py", line 336, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Users\Dell Pc\AppData\Local\Programs\Python\Python37-32\lib\smtplib.py", line 307, in _get_socket
self.source_address)
File "C:\Users\Dell Pc\AppData\Local\Programs\Python\Python37-32\lib\socket.py", line 707, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "C:\Users\Dell Pc\AppData\Local\Programs\Python\Python37-32\lib\socket.py", line 748, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed
How can I fix this error
Replace smtp.gamil.com by smtp.gmail.com.
There are no A/AAAA records for smtp.gamil.com (2021-01-07T13:08+00:00).
My program closes on name resolution error. This could happen when there is no internet or the other server is down. I want program to raise exception, but not exit. How do I do this. I'm using paho client.
File "/home/pi/.local/lib/python3.5/site-packages/paho/mqtt/client.py",
line 760, in connect
return self.reconnect()
File "/home/pi/.local/lib/python3.5/site-packages/paho/mqtt/client.py",
line 887, in reconnect
sock = socket.create_connection((self._host, self._port),
source_address=(self._bind_address, 0))
File "/usr/lib/python3.5/socket.py", line 694, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "/usr/lib/python3.5/socket.py", line 733, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto,
flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution
I'm trying to create a small app with Python and MySQL.
I managed to connect Python and MySQL using the MySQL connection. But now when I try to run this script to actually connect to the database:
import mysql.connector
mydb = mysql.connector.connect(
passwd="12345",
db="DB",
host="hostname",
user="root"
)
print(mydb)
I get a lot of errors like:
File "C:\Users\Krystian\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\network.py", line 485, in open_connection
socket.SOL_TCP)
File "C:\Users\Krystian\AppData\Local\Programs\Python\Python37-32\lib\socket.py", line 748, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed
File "c:/Users/Krystian/Desktop/DB/db.py", line 7, in <module>
user="root"
File "C:\Users\Krystian\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\__init__.py", line 179, in connect
return MySQLConnection(*args, **kwargs)
File "C:\Users\Krystian\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\connection.py", line 94, in __init__
self.connect(**kwargs)
File "C:\Users\Krystian\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\abstracts.py", line 722, in connect
self._open_connection()
File "C:\Users\Krystian\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\connection.py", line 207, in _open_connection
self._socket.open_connection()
File "C:\Users\Krystian\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\network.py", line 501, in open_connection
errno=2003, values=(self.get_address(), _strioerror(err)))
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on 'hostname:3306' (11001 getaddrinfo failed)
I tried other ways of conecting to Database but they didn't work and I'm not really sure what to do now.
Thanks in advance for any help!
EDIT1
As Juergen mentioned, after fixing the hostname most of the errors above are gone, but new ones showed up:
File "C:\Users\Krystian\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\connection.py", line 94, in __init__
self.connect(**kwargs)
File "C:\Users\Krystian\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\abstracts.py", line 722, in connect
self._open_connection()
File "C:\Users\Krystian\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\connection.py", line 211, in _open_connection
self._ssl)
File "C:\Users\Krystian\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\connection.py", line 141, in _do_auth
auth_plugin=self._auth_plugin)
File "C:\Users\Krystian\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\protocol.py", line 102, in make_auth
auth_data, ssl_enabled)
File "C:\Users\Krystian\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\protocol.py", line 58, in _auth_response
auth = get_auth_plugin(auth_plugin)(
File "C:\Users\Krystian\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\authentication.py", line 191, in get_auth_plugin
"Authentication plugin '{0}' is not supported".format(plugin_name))
mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supporte
I guess, your computer (where the database runs) is not named "hostname":
host="hostname",
If it is the local machine, try localhost. "hostname" is just a placeholder inside example coding. You always have to replace such.
About your edit:
Looks as your db server is misconfigured. Maybe you need that plugin that is named in the error message.
try this :
mysql.connector.connect(
host="localhost",
user="user_name",
passwd="db_password",
database="db_name")
Im currently having a problem with a Python program I made. The program is supposed to connect to google translate using the http.client module. My program works if im just connection to google.com, but it gives me an error when I try to connect to translate.google.com.
import urllib.request,re,http.client
while True:
print('')
question = input(">: ").replace(" ","%20").replace("?",'%3F')
x = "/#auto/es/%s"%(question)
conn = http.client.HTTPSConnection("www.translate.google.com",80)
http.client.HTTPConnection.connect(conn)
conn.request("GET",x)
response = conn.getresponse()
data = str(response.read())
conn.close()
print("Done")
Traceback (most recent call last):
File "P:\CS5\translater.py", line 9, in <module>
http.client.HTTPConnection.connect(conn)
File "C:\Program Files\Python35-32\lib\http\client.py", line 826, in connect
(self.host,self.port), self.timeout, self.source_address)
File "C:\Program Files\Python35-32\lib\socket.py", line 693, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "C:\Program Files\Python35-32\lib\socket.py", line 732, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11004] getaddrinfo failed