Forums

Error with Python3.3 mysql.connector

Hi, i'm trying to make a remote connection, this is my code of query

    import mysql.connector
cnx = mysql.connector.connect(host = 'xxx.net', user = 'xxxx', password = 'xxxx', database = 'remotedatabasexxx')
cursor = cnx.cursor()

cursor.execute("INSERT INTO file (name, content) VALUES (%s,%s)", (fileName, fileContent))
    cnx.commit()
    cursor.close()

Any code that i use after cursor = cnx.cursor() show my a "Syntax Error" (cursor.execute, cnx.commit() and cursor.clone() return an error if i put them after cursor = cnx.cursor())

Then, i go to my logerror and this is the error that it shows: 2014-04-24 05:20:07,286 : File "<frozen importlib._bootstrap>", line 605, in _requires_frozen_wrapper 2014-04-24 05:20:07,286 :ImportError: importlib._bootstrap is not a frozen module

It only happens when i exectute my app with any line that shows "Syntax Error"...

Of course i have this code on settings: DATABASES = { 'default': { 'ENGINE': 'mysql.connector.django', 'NAME': 'remotedatabasexxx', 'USER': 'xxxxx', 'PASSWORD': 'xxxxx', 'HOST': 'xxxx.net', 'PORT': '3306', } SOUTH_DATABASE_ADAPTERS = { 'default' : 'south.db.mysql' }

Please help me, I try and try but i can make it work.

Thanks!!

your code looks fine, and so does your database setup. It looks more like a Python 2 version of the mysql.connector library has got installed somehow. Can you show us a full traceback? Did you install mysql.connector manually or are you using our system default one?

Hi this is full traceback:

2014-04-24 14:55:01,888 :Traceback (most recent call last):
2014-04-24 14:55:01,903 :  File "/usr/local/lib/python3.3/dist-packages/django/core/handlers/base.py", line 101, in get_response
2014-04-24 14:55:01,904 :    resolver_match = resolver.resolve(request.path_info)
2014-04-24 14:55:01,904 :  File "/usr/local/lib/python3.3/dist-packages/django/core/urlresolvers.py", line 320, in resolve
2014-04-24 14:55:01,904 :    sub_match = pattern.resolve(new_path)
2014-04-24 14:55:01,904 :  File "/usr/local/lib/python3.3/dist-packages/django/core/urlresolvers.py", line 320, in resolve
2014-04-24 14:55:01,905 :    sub_match = pattern.resolve(new_path)
2014-04-24 14:55:01,905 :  File "/usr/local/lib/python3.3/dist-packages/django/core/urlresolvers.py", line 222, in resolve
2014-04-24 14:55:01,905 :    return ResolverMatch(self.callback, args, kwargs, self.name)
2014-04-24 14:55:01,905 :  File "/usr/local/lib/python3.3/dist-packages/django/core/urlresolvers.py", line 229, in callback
2014-04-24 14:55:01,906 :    self._callback = get_callable(self._callback_str)
2014-04-24 14:55:01,906 :  File "/usr/local/lib/python3.3/dist-packages/django/utils/functional.py", line 32, in wrapper
2014-04-24 14:55:01,906 :    result = func(*args)
2014-04-24 14:55:01,906 :  File "/usr/local/lib/python3.3/dist-packages/django/core/urlresolvers.py", line 96, in get_callable
2014-04-24 14:55:01,906 :    mod = import_module(mod_name)
2014-04-24 14:55:01,907 :  File "/usr/lib/python3.3/importlib/__init__.py", line 90, in import_module
2014-04-24 14:55:01,907 :    return _bootstrap._gcd_import(name[level:], package, level)
2014-04-24 14:55:01,907 :  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
2014-04-24 14:55:01,910 :  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
2014-04-24 14:55:01,910 :  File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
2014-04-24 14:55:01,911 :  File "<frozen importlib._bootstrap>", line 584, in _check_name_wrapper
2014-04-24 14:55:01,911 :  File "<frozen importlib._bootstrap>", line 1022, in load_module
2014-04-24 14:55:01,911 :  File "<frozen importlib._bootstrap>", line 1003, in load_module
2014-04-24 14:55:01,911 :  File "<frozen importlib._bootstrap>", line 560, in module_for_loader_wrapper
2014-04-24 14:55:01,912 :  File "<frozen importlib._bootstrap>", line 853, in _load_module
2014-04-24 14:55:01,912 :  File "<frozen importlib._bootstrap>", line 980, in get_code
2014-04-24 14:55:01,912 :  File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
2014-04-24 14:55:01,913 :  File "/home/noemileon/myproject/myproject/myapp/views.py", line 36
2014-04-24 14:55:01,913 :    cnx.commit()
2014-04-24 14:55:01,913 :               ^
2014-04-24 14:55:01,913 :IndentationError: unindent does not match any outer indentation level
2014-04-24 14:55:01,913 :
2014-04-24 14:55:01,913 :During handling of the above exception, another exception occurred:
2014-04-24 14:55:01,913 :
2014-04-24 14:55:01,913 :Traceback (most recent call last):
2014-04-24 14:55:01,914 :  File "/bin/user_wsgi_wrapper.py", line 67, in __call__
2014-04-24 14:55:01,914 :    self.error_log_file.logger.exception("Error running WSGI application")
2014-04-24 14:55:01,914 :  File "/usr/lib/python3.3/logging/__init__.py", line 1269, in exception
2014-04-24 14:55:01,916 :    self.error(msg, *args, **kwargs)
2014-04-24 14:55:01,916 :  File "/usr/lib/python3.3/logging/__init__.py", line 1262, in error
2014-04-24 14:55:01,917 :    self._log(ERROR, msg, args, **kwargs)
2014-04-24 14:55:01,917 :  File "/usr/lib/python3.3/logging/__init__.py", line 1368, in _log
2014-04-24 14:55:01,918 :    self.handle(record)
2014-04-24 14:55:01,918 :  File "/usr/lib/python3.3/logging/__init__.py", line 1377, in handle
2014-04-24 14:55:01,919 :    if (not self.disabled) and self.filter(record):
2014-04-24 14:55:01,919 :  File "/usr/lib/python3.3/logging/__init__.py", line 687, in filter
2014-04-24 14:55:01,920 :    for f in self.filters:
2014-04-24 14:55:01,920 :  File "/bin/user_wsgi_wrapper.py", line 59, in __call__
2014-04-24 14:55:01,920 :    app_iterator = self.app(environ, start_response)
2014-04-24 14:55:01,920 :  File "/usr/local/lib/python3.3/dist-packages/django/core/handlers/wsgi.py", line 206, in __call__
2014-04-24 14:55:01,921 :    response = self.get_response(request)
2014-04-24 14:55:01,921 :  File "/usr/local/lib/python3.3/dist-packages/django/core/handlers/base.py", line 196, in get_response
2014-04-24 14:55:01,922 :    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
2014-04-24 14:55:01,922 :  File "/usr/local/lib/python3.3/dist-packages/django/core/handlers/base.py", line 231, in handle_uncaught_exception
2014-04-24 14:55:01,922 :    return debug.technical_500_response(request, *exc_info)
2014-04-24 14:55:01,922 :  File "/usr/local/lib/python3.3/dist-packages/django/views/debug.py", line 69, in technical_500_response
2014-04-24 14:55:01,922 :    html = reporter.get_traceback_html()
2014-04-24 14:55:01,923 :  File "/usr/local/lib/python3.3/dist-packages/django/views/debug.py", line 323, in get_traceback_html
2014-04-24 14:55:01,923 :    c = Context(self.get_traceback_data())
2014-04-24 14:55:01,923 :  File "/usr/local/lib/python3.3/dist-packages/django/views/debug.py", line 281, in get_traceback_data
2014-04-24 14:55:01,923 :    frames = self.get_traceback_frames()
2014-04-24 14:55:01,924 :  File "/usr/local/lib/python3.3/dist-packages/django/views/debug.py", line 428, in get_traceback_frames
2014-04-24 14:55:01,924 :    pre_context_lineno, pre_context, context_line, post_context = self._get_lines_from_file(filename, lineno, 7, loader, module_name)
2014-04-24 14:55:01,924 :  File "/usr/local/lib/python3.3/dist-packages/django/views/debug.py", line 379, in _get_lines_from_file
2014-04-24 14:55:01,924 :    source = loader.get_source(module_name)
2014-04-24 14:55:01,925 :  File "<frozen importlib._bootstrap>", line 605, in _requires_frozen_wrapper
2014-04-24 14:55:01,925 :ImportError: importlib._bootstrap is not a frozen module
2014-04-24 14:55:30,047 :Traceback (most recent call last):
2014-04-24 14:55:30,071 :  File "/usr/local/lib/python3.3/dist-packages/django/core/handlers/base.py", line 101, in get_response
2014-04-24 14:55:30,072 :    resolver_match = resolver.resolve(request.path_info)
2014-04-24 14:55:30,072 :  File "/usr/local/lib/python3.3/dist-packages/django/core/urlresolvers.py", line 320, in resolve
2014-04-24 14:55:30,072 :    sub_match = pattern.resolve(new_path)
2014-04-24 14:55:30,072 :  File "/usr/local/lib/python3.3/dist-packages/django/core/urlresolvers.py", line 320, in resolve
2014-04-24 14:55:30,073 :    sub_match = pattern.resolve(new_path)
2014-04-24 14:55:30,073 :  File "/usr/local/lib/python3.3/dist-packages/django/core/urlresolvers.py", line 222, in resolve
2014-04-24 14:55:30,073 :    return ResolverMatch(self.callback, args, kwargs, self.name)
2014-04-24 14:55:30,073 :  File "/usr/local/lib/python3.3/dist-packages/django/core/urlresolvers.py", line 229, in callback
2014-04-24 14:55:30,073 :    self._callback = get_callable(self._callback_str)
2014-04-24 14:55:30,074 :  File "/usr/local/lib/python3.3/dist-packages/django/utils/functional.py", line 32, in wrapper
2014-04-24 14:55:30,074 :    result = func(*args)
2014-04-24 14:55:30,074 :  File "/usr/local/lib/python3.3/dist-packages/django/core/urlresolvers.py", line 96, in get_callable
2014-04-24 14:55:30,074 :    mod = import_module(mod_name)
2014-04-24 14:55:30,074 :  File "/usr/lib/python3.3/importlib/__init__.py", line 90, in import_module
2014-04-24 14:55:30,075 :    return _bootstrap._gcd_import(name[level:], package, level)
2014-04-24 14:55:30,075 :  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
2014-04-24 14:55:30,077 :  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
2014-04-24 14:55:30,077 :  File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
2014-04-24 14:55:30,077 :  File "<frozen importlib._bootstrap>", line 584, in _check_name_wrapper
2014-04-24 14:55:30,078 :  File "<frozen importlib._bootstrap>", line 1022, in load_module
2014-04-24 14:55:30,078 :  File "<frozen importlib._bootstrap>", line 1003, in load_module
2014-04-24 14:55:30,078 :  File "<frozen importlib._bootstrap>", line 560, in module_for_loader_wrapper
2014-04-24 14:55:30,079 :  File "<frozen importlib._bootstrap>", line 853, in _load_module
2014-04-24 14:55:30,079 :  File "<frozen importlib._bootstrap>", line 980, in get_code
2014-04-24 14:55:30,079 :  File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
2014-04-24 14:55:30,079 :  File "/home/noemileon/myproject/myproject/myapp/views.py", line 36
2014-04-24 14:55:30,080 :    cnx.commit()
2014-04-24 14:55:30,080 :               ^
2014-04-24 14:55:30,080 :IndentationError: unindent does not match any outer indentation level
2014-04-24 14:55:30,080 :
2014-04-24 14:55:30,080 :During handling of the above exception, another exception occurred:
2014-04-24 14:55:30,080 :
2014-04-24 14:55:30,080 :Traceback (most recent call last):
2014-04-24 14:55:30,080 :  File "/bin/user_wsgi_wrapper.py", line 67, in __call__
2014-04-24 14:55:30,081 :    self.error_log_file.logger.exception("Error running WSGI application")
2014-04-24 14:55:30,081 :  File "/usr/lib/python3.3/logging/__init__.py", line 1269, in exception
2014-04-24 14:55:30,082 :    self.error(msg, *args, **kwargs)
2014-04-24 14:55:30,082 :  File "/usr/lib/python3.3/logging/__init__.py", line 1262, in error
2014-04-24 14:55:30,082 :    self._log(ERROR, msg, args, **kwargs)
2014-04-24 14:55:30,083 :  File "/usr/lib/python3.3/logging/__init__.py", line 1368, in _log
2014-04-24 14:55:30,083 :    self.handle(record)
2014-04-24 14:55:30,083 :  File "/usr/lib/python3.3/logging/__init__.py", line 1377, in handle
2014-04-24 14:55:30,084 :    if (not self.disabled) and self.filter(record):
2014-04-24 14:55:30,084 :  File "/usr/lib/python3.3/logging/__init__.py", line 687, in filter
2014-04-24 14:55:30,085 :    for f in self.filters:
2014-04-24 14:55:30,085 :  File "/bin/user_wsgi_wrapper.py", line 59, in __call__
2014-04-24 14:55:30,085 :    app_iterator = self.app(environ, start_response)
2014-04-24 14:55:30,085 :  File "/usr/local/lib/python3.3/dist-packages/django/core/handlers/wsgi.py", line 206, in __call__
2014-04-24 14:55:30,086 :    response = self.get_response(request)
2014-04-24 14:55:30,086 :  File "/usr/local/lib/python3.3/dist-packages/django/core/handlers/base.py", line 196, in get_response
2014-04-24 14:55:30,086 :    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
2014-04-24 14:55:30,087 :  File "/usr/local/lib/python3.3/dist-packages/django/core/handlers/base.py", line 231, in handle_uncaught_exception
2014-04-24 14:55:30,087 :    return debug.technical_500_response(request, *exc_info)
2014-04-24 14:55:30,087 :  File "/usr/local/lib/python3.3/dist-packages/django/views/debug.py", line 69, in technical_500_response
2014-04-24 14:55:30,087 :    html = reporter.get_traceback_html()
2014-04-24 14:55:30,087 :  File "/usr/local/lib/python3.3/dist-packages/django/views/debug.py", line 323, in get_traceback_html
2014-04-24 14:55:30,088 :    c = Context(self.get_traceback_data())
2014-04-24 14:55:30,088 :  File "/usr/local/lib/python3.3/dist-packages/django/views/debug.py", line 281, in get_traceback_data
2014-04-24 14:55:30,088 :    frames = self.get_traceback_frames()
2014-04-24 14:55:30,088 :  File "/usr/local/lib/python3.3/dist-packages/django/views/debug.py", line 428, in get_traceback_frames
2014-04-24 14:55:30,089 :    pre_context_lineno, pre_context, context_line, post_context = self._get_lines_from_file(filename, lineno, 7, loader, module_name)
2014-04-24 14:55:30,089 :  File "/usr/local/lib/python3.3/dist-packages/django/views/debug.py", line 379, in _get_lines_from_file
2014-04-24 14:55:30,089 :    source = loader.get_source(module_name)
2014-04-24 14:55:30,089 :  File "<frozen importlib._bootstrap>", line 605, in _requires_frozen_wrapper
2014-04-24 14:55:30,090 :ImportError: importlib._bootstrap is not a frozen module

[edited by admin: formatting]

And I install mysql.connector like says in your help: https://www.pythonanywhere.com/wiki/UsingMySQL exactly on "MySQL with Python 3 for Django".. Thank you, please help :(

It looks like the real problem here is this bit:

2014-04-24 14:55:30,079 :  File "/home/noemileon/myproject/myproject/myapp/views.py", line 36
2014-04-24 14:55:30,080 :    cnx.commit()
2014-04-24 14:55:30,080 :               ^
2014-04-24 14:55:30,080 :IndentationError: unindent does not match any outer indentation level

Is it indented correctly? If it looks like it is indented correctly, are you perhaps using tabs instead of spaces there?