Re: help me plz: getting error while importing csv file into database

37 views
Skip to first unread message

ram manoj Vuyyuru

unread,
Jun 18, 2021, 2:22:40 PM6/18/21
to django...@googlegroups.com
while running this project  getting this error 

 File "C:\ProgramData\Anaconda3\lib\site-packages\django\urls\resolvers.py", line 347, in _check_pattern_name
    if self.pattern.name is not None and ":" in self.pattern.name:
TypeError: argument of type 'type' is not iterable


thank you 

On Fri, Jun 18, 2021 at 10:52 PM ram manoj Vuyyuru <rammano...@gmail.com> wrote:
Hi 
i am trying to import the csv file data into database 
 my views.py 
def Filter(request):
    if request.method=="POST":
        form = DataForm(request.POST, request.FILES)
        if form.is_valid():
            initial_obj = form.save(commit=False)
            data=initial_obj['data']
            path="C:\\Users\\ramma\\Downloads\\assesment.csv"
            os.chdir(path)

            with open('assesment.csv'as csvfile:
                reader = csv.DictReader(csvfile)
                for row in reader:
                    file=data(name=row['product'],)

            initial_obj.save()
            file.save()
            return redirect('/')
        else:
            return render(request,'index.html',{'form':form})
    else:
        return render(request,'index.html',{'form':form})


def search(request):
    list = data.objects.all()
    data_filter = DataFilter(request.GET, queryset=list)
    return render(request'product.html', {'filter'data_filter})

ram manoj Vuyyuru

unread,
Jun 18, 2021, 2:22:41 PM6/18/21
to django...@googlegroups.com

Heron

unread,
Jun 19, 2021, 8:19:09 AM6/19/21
to django...@googlegroups.com
Hello,

I getting problem to connect to database only when run "migrate". I'm able to use on apache/wsgi and runserver, so it's seens that connection to database is okay. Dango is running on docker.

Anyone can help me ?





bash-4.2# python manage.py migrate
/usr/local/lib/python2.7/site-packages/jwt/utils.py:8: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in the next release.
  from cryptography.hazmat.primitives.asymmetric.utils import (
Traceback (most recent call last):
  File "manage.py", line 46, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 327, in execute
    self.check()
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 359, in check
    include_deployment_checks=include_deployment_checks,
  File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 61, in _run_checks
    issues = run_checks(tags=[Tags.database])
  File "/usr/local/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/usr/local/lib/python2.7/site-packages/django/core/checks/database.py", line 10, in check_database_backends
    issues.extend(conn.validation.check(**kwargs))
  File "/usr/local/lib/python2.7/site-packages/django/db/backends/mysql/validation.py", line 9, in check
    issues.extend(self._check_sql_mode(**kwargs))
  File "/usr/local/lib/python2.7/site-packages/django/db/backends/mysql/validation.py", line 13, in _check_sql_mode
    with self.connection.cursor() as cursor:
  File "/usr/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 254, in cursor
    return self._cursor()
  File "/usr/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 229, in _cursor
    self.ensure_connection()
  File "/usr/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
    self.connect()
  File "/usr/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
    self.connect()
  File "/usr/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 189, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/usr/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 274, in get_new_connection
    conn = Database.connect(**conn_params)
  File "/usr/local/lib64/python2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/usr/local/lib64/python2.7/site-packages/MySQLdb/connections.py", line 193, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on '192.168.201.193' (113)")
bash-4.2# python manage.py check
/usr/local/lib/python2.7/site-packages/jwt/utils.py:8: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in the next release.
  from cryptography.hazmat.primitives.asymmetric.utils import (

2021-06-18 20:00:05 [DEBUG] [boto:provider:get_credentials:280] [MainThread]
Using access key provided by client.

2021-06-18 20:00:05 [DEBUG] [boto:provider:get_credentials:307] [MainThread]
Using secret key provided by client.

2021-06-18 20:00:05 [DEBUG] [boto:provider:get_credentials:280] [MainThread]
Using access key provided by client.

2021-06-18 20:00:05 [DEBUG] [boto:provider:get_credentials:307] [MainThread]
Using secret key provided by client.
System check identified no issues (0 silenced).

Regards,
_________________

Heron
her...@gmail.com
_________________

Luciano Martins

unread,
Jun 20, 2021, 6:28:19 AM6/20/21
to Django users
you have to pass the 'path' variable into open I believe that's it

Luciano Martins

unread,
Jun 20, 2021, 6:31:39 AM6/20/21
to Django users

have you configured mysql database in settings.py?

Heron

unread,
Jun 21, 2021, 4:45:31 PM6/21/21
to django...@googlegroups.com
Yes,

And its works fine with runserver, check or with apache/wscgi

regards,
_________________

Heron
her...@gmail.com
_________________


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/661df4a8-0681-4777-946f-bd11dfcb72efn%40googlegroups.com.

Aziz Meknassi

unread,
Jun 22, 2021, 2:30:41 PM6/22/21
to django...@googlegroups.com
Hi Heron,

To make sure you are talking to your database, 
in your project and in your command line, type
 python manage.py shell 
then import your model

If for example you have prodApp and model Product
from prodApp.models import Product
prd = Product.objects.all()
print(prd) 
Please checkout ORM (  https://docs.djangoproject.com/en/3.2/topics/db/queries/ )operations, if you can talk to the database via ORM and see the data in your database, then everything is setup correctly and you need to look into the settings etc

I hope this helps

Kind regards
Aziz Meknassi



--
Kind regards
Aziz Meknassi
Tel: 07552128860

Heron

unread,
Jun 22, 2021, 5:29:05 PM6/22/21
to django...@googlegroups.com
Thank you Aziz


Regards,
_________________

Heron
her...@gmail.com
_________________

Reply all
Reply to author
Forward
0 new messages