PyQt5: cannot write cookie to file using QFile
<p>I have a file named <em>cookies.txt</em>.</p>

<pre><code>fd = QFile(":/cookies.txt")
available_cookies = QtNetwork.QNetworkCookieJar().allCookies()
for cookie in available_cookies:
   print(cookie.toRawForm(1))
   QTextStream(cookie.toRawForm(1), fd.open(QIODevice.WriteOnly))
fd.close()
</code></pre>

<p>Here is my full traceback:</p>

<pre><code>QTextStream(cookie.toRawForm(1),        fd.open(QIODevice.WriteOnly))
TypeError: arguments did not match any overloaded call:
QTextStream(): too many arguments
QTextStream(QIODevice): argument 1 has unexpected type 'QByteArray'
QTextStream(QByteArray, mode: Union[QIODevice.OpenMode,    QIODevice.OpenModeFlag] = QIODevice.ReadWrite): argument 2 has unexpected type 'bool'
</code></pre>

<p>I am following the C++ documentation, and I am having trouble writing the corresponding python syntax.</p>

<p>Are you really trying to write to a resource path? Resources are read-only, so that is not going to work.</p>

<p>To write to a non-resource path:</p>

<pre><code>fd = QFile('/tmp/cookies.txt')
if fd.open(QIODevice.WriteOnly):
    available_cookies = QtNetwork.QNetworkCookieJar().allCookies()
    stream = QTextStream(fd)
    for cookie in available_cookies:
        data = cookie.toRawForm(QtNetwork.QNetworkCookie.Full)
        stream &lt;&lt; data
    fd.close()
</code></pre>

python qt5 pyqt5 qfile qtextstream