def add_serialized(self, data, format, context=None): if isinstance(data, str): data = data.encode('utf-8') if self.curl: fp = tempfile.NamedTemporaryFile(delete=False) fp.write(data) tmp = fp.name fp.close() self.add_serialized_file(tmp, format, context) os.unlink(tmp) else: # Requests 1.2 has a bug that leads to duplicated # Content-type headers under at least python 3, and # under py 3.3 this causes problem with both fuseki # and sesame. see end of prepare_body in models.py # (line 381). one way of working around this bug is # to use a streaming request, so we wrap our data in a # file-like object. All ways are good except the bad. datastream = BytesIO(data) datastream.len = len(data) headers = {'Content-Type': self._contenttype[format] + "; charset=UTF-8"} resp = requests.post(self._statements_url(context), headers=headers, data=datastream) resp.raise_for_status()