r/learnpython • u/Alive_Hotel6668 • 21d ago
I am not sure why this user defined function is not working.
n=1
def continution():
x=input('Do you want to continue?')
if x=='yes':
global n
n=1
else:
global n
n=0
if i input yes there is a big text about an error if i eneter no still something similar
(This is part of a bigger sql python interface project)
This is the error:
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\mysql\connector\network.py", line 165, in _send_pkt
sock.sendall(pkt)
OSError: [WinError 10038] An operation was attempted on something that is not a socket
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "F:\AA main project.py", line 12, in <module>
cur=c.cursor()
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\mysql\connector\cursor.py", line 416, in execute
self._connection.cmd_query(
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\mysql\connector\opentelemetry\context_propagation.py", line 97, in wrapper
return method(cnx, *args, **kwargs)
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\mysql\connector_decorating.py", line 89, in handle_cnx_method
raise err
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\mysql\connector_decorating.py", line 85, in handle_cnx_method
return cnx_method(cnx, *args, **kwargs)
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\mysql\connector\connection.py", line 985, in cmd_query
self._send_cmd(
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\mysql\connector_decorating.py", line 89, in handle_cnx_method
raise err
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\mysql\connector_decorating.py", line 85, in handle_cnx_method
return cnx_method(cnx, *args, **kwargs)
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\mysql\connector\connection.py", line 507, in _send_cmd
self._socket.send(
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\mysql\connector\network.py", line 650, in send
self._netbroker.send(
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\mysql\connector\network.py", line 223, in send
self._send_pkt(
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\mysql\connector\network.py", line 169, in _send_pkt
raise OperationalError(
mysql.connector.errors.OperationalError: 2055: Lost connection to MySQL server at 'localhost:3306', system error: Errno 10038: An operation was attempted on something that is not a socket
2
u/AmanBabuHemant 21d ago
Can you make sure that your SQL Server is running when you tried it ?
23
u/danielroseman 21d ago
Learning to read the error messages you get is a vital part of learning to program. In this case, the error does not mention your function at all, and only talks about MySql, so it's not clear why you think the function has anything to do with it.
In fact the only reference to your code is here:
So it is clear that you are calling MySQL in a part of the code you have not shown.
14
u/JaguarMammoth6231 21d ago
That error has nothing to do with the
continuationfunction.5
u/TensionCareful 21d ago
Error said lost connection to MySQL server..
2
u/woooee 21d ago
Your function runs. It is what happens in the program after the function returns, which you didn't post.
3
u/Prestigious-Lion-878 21d ago
You have a typo I think.
continution()
VRs
continuation()
1
u/JamzTyson 20d ago
Please ensure that the code you post is properly formatted.
1
u/Chorizo_n_eggs 21d ago
Should it be continuation?