How can I properly serialize wikidata SPARQL queries answers?
<p>I have the following  example of querying wikidata via Python's SPARQLWrapper:</p>

<pre><code>import rdflib, urllib
from SPARQLWrapper import SPARQLWrapper, JSON, XML, TURTLE, RDF, N3 
from rdflib import Graph, Namespace, URIRef, RDF#, RDFS, Literal    

def graph_full(uri, f)
    sparql = SPARQLWrapper('https://query.wikidata.org/sparql')
    sparql.setQuery('''
    PREFIX entity: &lt;http://www.wikidata.org/entity/&gt;

    SELECT ?predicate ?object WHERE {
        &lt;'''+urllib.unquote(uri).encode("utf8")+'''&gt; ?predicate ?object .
    } LIMIT 100
    ''')

    sparql.setReturnFormat(N3)
    results = sparql.query().convert()
    #print results.serialize()

    print type(results)
    g = Graph()
    g.parse(results)
    print g 
    #g.serialize(f, format="n3")

if __name__ == '__main__':
    graph_full("entity:Q76", "wikidata/output.nt")
</code></pre>

<p>I want to serialize the result of the SPARQL query and save it to a file. This seems to always throw the following error:</p>

<pre><code>Exception: Unexpected type '&lt;type 'instance'&gt;' for source    '&lt;xml.dom.minidom.Document instance at 0x7fa11e3715a8&gt;'
</code></pre>

<p>Using similar code against DBpedia SPARQL endpoints throws no erros.</p>