title: Writing Unicode to .docx file
body: <p>Is there any way to write unicode characters to docx files? I tried <a href="https://python-docx.readthedocs.io/" rel="nofollow noreferrer">python-docx</a> but, it's giving me <code>TypeError</code>.</p>
  
  <p><b>Traceback</b></p>
  
  <blockquote>
    <p>Traceback (most recent call last):</p>
    
    <p>File "&lt; ipython-input-1-ba89c735995d >", line 1, in 
        runfile('H:/Python/Practice/new/download.py', wdir='H:/Python/Practice/new')</p>
    
    <p>File "C:\Program Files\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
        execfile(filename, namespace)</p>
    
    <p>File "C:\Program Files\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
        exec(compile(f.read(), filename, 'exec'), namespace)</p>
    
    <p>File "H:/Python/Practice/new/download.py", line 37, in 
        document.add_paragraph(story.encode("utf-8"))</p>
    
    <p>File "C:\Program Files\Anaconda3\lib\site-packages\docx\document.py", line 63, in add_paragraph
        return self._body.add_paragraph(text, style)</p>
    
    <p>File "C:\Program Files\Anaconda3\lib\site-packages\docx\blkcntnr.py", line 36, in add_paragraph
        paragraph.add_run(text)</p>
    
    <p>File "C:\Program Files\Anaconda3\lib\site-packages\docx\text\paragraph.py", line 37, in add_run
        run.text = text</p>
    
    <p>File "C:\Program Files\Anaconda3\lib\site-packages\docx\text\run.py", line 163, in text
        self._r.text = text</p>
    
    <p>File "C:\Program Files\Anaconda3\lib\site-packages\docx\oxml\text\run.py", line 104, in text
        _RunContentAppender.append_to_run_from_text(self, text)</p>
    
    <p>File "C:\Program Files\Anaconda3\lib\site-packages\docx\oxml\text\run.py", line 134, in append_to_run_from_text
        appender.add_text(text)</p>
    
    <p>File "C:\Program Files\Anaconda3\lib\site-packages\docx\oxml\text\run.py", line 142, in add_text
        self.add_char(char)</p>
    
    <p>File "C:\Program Files\Anaconda3\lib\site-packages\docx\oxml\text\run.py", line 156, in add_char
        elif char in '\r\n':</p>
    
    <p>TypeError: 'in &lt; string >' requires string as left operand, not int</p>
  </blockquote>
  
  <p>I was trying to scrape a website and write the texts to a MS Word file. Texts are in local language (Bangla). When I print <code>story</code> on console it prints the whole texts perfectly.</p>
  
  <p><b>Code</b></p>
  
  <pre><code>import requests
  from docx import Document
  from bs4 import BeautifulSoup
  
  url = "some url"
  response = requests.get(url)
  soup = BeautifulSoup(response.text, "lxml")
  
  story = soup.find("div", {"dir": "ltr"}).get_text().replace("&lt;br /&gt;", "\n", len(response.text))
  
  title = "title"
  document = Document()
  document.add_heading(title, 0)
  document.add_paragraph(story.encode("utf-8"))
  document.save(title + ".docx")
  </code></pre>