---
# System prepended metadata

title: export_function.py
tags: [z_archive]

---

# export_function.py
- The [script](https://github.com/CECSpecialistI/UWLibCatProfiles/blob/e55484828e2cbac578981e915104a96696972c2c/scripts/export_function.py) is currently in **UWLibCatProfiles** (link to version in [tree e55484828e](https://github.com/CECSpecialistI/UWLibCatProfiles/tree/e55484828e2cbac578981e915104a96696972c2c))
- Alexis K.M. kindly provided overviews for both of these fixes before finishing up her position in CAMS, they are linked below (both are located in the [UWL CaMS Linked Data Team shared G. drive](https://drive.google.com/drive/folders/0AOh1bCss-RsNUk9PVA) > [documentation and drafts folder](https://drive.google.com/drive/folders/1fc68QGEzZ8NVXsxzt2QvJ2-6oNz5mkKn))

## To-do:
1. Fix issues encountered by Melissa 2020-05-08 (see error message at bottom\* of this note) - see AKM recommendation [sin2fuseki export updates](https://docs.google.com/document/d/1TTBbJrNQGaR0nUbedBJtwa1PttukCkALGjYQV0Gk1v8/edit)
2. Add functionality to create provenance statements and load these in Fuseki along with Sinopia export triples - see recommendation [sin2fuseki prov statement](https://docs.google.com/document/d/1AbzB4lk0YCu_6CmpmVzugHBoUUeZieQ90UvWSB7klCg/edit)
## Other notes
- This script loads Trellis export triples into Fuseki and also serializes and saves triples locally in RDF/XML and Turtle; these are saved in `export_xml` and `export_ttl` folders in multiple files, one for each resource (this matches the structure of Sinopia exports, which are provided in multiple JSON-LD files, one for each resource)
- [rdfLibSer.py](https://github.com/uwlib-cams/webviews/blob/3412f1073ab1bf13ca1c2e0a88d6a0f1b93bdd3d/python/rdfLibSer.py) is a modification of this script; it was changed so that it would serialize and save a single file containing all triples (RDF/XML only), as opposed to multiple files as described above
## 2020-05-08 error message
```
python3 export_function.py
...
retrieving graph uris
...
saving downloaded graphs locally
...
clearing graph
...
update succeeded
...
updating fuseki
Traceback (most recent call last):
  File "/home/mcm104/.local/lib/python3.6/site-packages/SPARQLWrapper/Wrapper.py", line 1073, in _query
    response = urlopener(request)
  File "/usr/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.6/urllib/request.py", line 532, in open
    response = meth(req, response)
  File "/usr/lib/python3.6/urllib/request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python3.6/urllib/request.py", line 570, in error
    return self._call_chain(*args)
  File "/usr/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.6/urllib/request.py", line 650, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "export_function.py", line 94, in <module>
    results = sparql.query().convert()
  File "/home/mcm104/.local/lib/python3.6/site-packages/SPARQLWrapper/Wrapper.py", line 1107, in query
    return QueryResult(self._query())
  File "/home/mcm104/.local/lib/python3.6/site-packages/SPARQLWrapper/Wrapper.py", line 1077, in _query
    raise QueryBadFormed(e.read())
SPARQLWrapper.SPARQLExceptions.QueryBadFormed: QueryBadFormed: a bad request has been sent to the endpoint, probably the sparql query is bad formed.
Response:
b'<!DOCTYPE html><html><head><title>Apache Tomcat/9.0.0.M15 - Error report</title><style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style> </head><body><h1>HTTP Status 400 - Unknown content type for triples: [application/x-www-form-urlencoded]</h1><div class="line"></div><p><b>type</b> Status report</p><p><b>message</b> <u>Unknown content type for triples: [application/x-www-form-urlencoded]</u></p><p><b>description</b> <u>The request sent by the client was syntactically incorrect.</u></p><hr class="line"><h3>Apache Tomcat/9.0.0.M15</h3></body></html>'
```
## More (random) notes re: export_function.py
To run AKM's Sinopia-to-Fuseki script:

- Install (pip3):
	- rdflib
	- SPARQLwrapper
	- random
	- os*
	
- NOTE:
	- random does not seem to be needed by the script... the import has been commented out
	- os is included in Python3 by default

- AKM also notes:
	- I'll probably want requests


