ValueError: script argument must be unicode. - Python3.5, SQLite3
<p>I'm writing following python script:</p>

<pre class="lang-py prettyprint-override"><code>import sqlite3
import sys

if len(sys.argv) &lt; 2:
    print("Error: You must supply at least SQL script.")
    print("Usage: %s table.db ./sql-dump.sql" % (sys.argv[0]))
    sys.exit(1)

script_path = sys.argv[1]

if len(sys.argv) == 3:
    db = sys.argv[2]
else:
    db = ":memory:"

try:
    con = sqlite3.connect(db)
    with con:
        cur = con.cursor()
        with open(script_path,'rb') as f:
            cur.executescript(f.read())
except sqlite3.Error as err:
    print("Error occured: %s" % err)
</code></pre>



<p>I saved this program as <strong>sqlite_import.py</strong>.
I have a database file named <strong>test.db</strong> and a SQL file <strong>world.sql</strong>.
Now I tried to run program as:</p>

<pre class="lang-py prettyprint-override"><code>sqlite_import.py test.db world.sql
</code></pre>



<p>But it shows me error like following:</p>

<pre class="lang-py prettyprint-override"><code>Traceback (most recent call last):
  File "C:\Users\Jarvis\OneDrive\Documents\Python\Python Data Visualization Cookbook, 2E\2 Knowing Your Data\sqlite_import.py", line 21, in &lt;module&gt;
    cur.executescript(f.read())
ValueError: script argument must be unicode.
</code></pre>



<p>Help me to fix this.</p>

<p>You opened the script file as <em>binary</em>:</p>

<pre><code>with open(script_path,'rb') as f:
</code></pre>

<p>This produces a <code>b'...'</code> bytes value, not a Unicode <code>str</code> object. Remove the <code>b</code>, and perhaps add an <code>encoding</code> argument to specific what codec to use to decode the data with.</p>

python unicode sqlite3