[Answered ]-Unable to insert specific data in database in Sqlite3 Python Django

1πŸ‘

βœ…

I found the solution. In case you are using Django, please refer to Burhan Khalid easy solution that solves everything:

from yourapp.models import url_list

new_url = url_list(url_id=url_i, url_name=url_n, url_title=url_t)
new_url.save()

BUT, if you are not working in models or Django (or Both) and involves a normal table, let me draw your attention to the fact that the url_t variable is neither a string nor a unicode variable. When I did this:

type(url_t)

I got the type of url_t and it returned:

<class 'bs4.something'>

Which is something we don’t want.

We want:

<type 'unicode'>

To convert it to unicode, just do the following:

unicode(url_t)

Even after converting it to unicode, I noticed the problem persisted. Then, with a few more experiments, I did the following:

url_t=str(url_t)
url_t=url_t[1:]

Voila. Problem solved.

πŸ‘€user3504239

1πŸ‘

Instead of messing with cursors and raw SQL, use the database api:

from yourapp.models import url_list

new_url = url_list(url_id=url_i, url_name=url_n, url_title=url_t)
new_url.save()
πŸ‘€Burhan Khalid

Leave a comment