188BET靠谱吗How to use pyzotero to access Zotero 7 beta local API server ?
As is shown in this page:
188BET靠谱吗https://groups.google.com/g/zotero-dev/c/ElvHhIFAXrY/m/fA7SKKwsAgAJ
188BET靠谱吗Zotero has already set up a local API server since Zotero 7 beta 88, and the local API shares almost the same interfaces with online server API.
188BET靠谱吗I'm going to access my local zotero user library via pyzotero, and luckily found that the API endpoint in pyzotero can be accessed and set as another url base address ( 188BET靠谱吗https://github.com/urschrei/pyzotero/blob/9ca972620cd7927d9de265c1b7c3ce270e5ef9d3/src/pyzotero/zotero.py#L270).
As is shown in the local server code ( 188BET靠谱吗https://github.com/zotero/zotero/blob/main/chrome/content/zotero/xpcom/localAPI/server_localAPI.js), the local API server can be accessed at http://localhost:23119/api/.
188BET靠谱吗However, when I have set zotero.Zotero.endpoint to http:///localhost:23119/api/, the request URL is not properly generated:
```python
188BET靠谱吗from pyzotero import zotero
188BET靠谱吗zot = zotero.Zotero(ZOTERO_LIBRARY_ID, "user", ZOTERO_LOCAL_API_KEY)
zot.endpoint = " http://localhost:23119/api/"
items = zot.top(limit=10)
```
Has caused:
```
Traceback (most recent call last):
188BET靠谱吗File "C:\Users\xxxx\miniforge3\envs\MinerU\lib\site-packages\pyzotero\zotero.py", line 401, in _retrieve_data
self.request.raise_for_status()
File "C:\Users\xxxx\miniforge3\envs\MinerU\lib\site-packages\requests\models.py", line 1024, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: http://localhost:23119/users/0000000/items/top?limit=10&format=json
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "F:\paper-qa-utils\zot.py", line 9, in
items = zot.top(limit=10)
188BET靠谱吗File "C:\Users\xxxx\miniforge3\envs\MinerU\lib\site-packages\pyzotero\zotero.py", line 154, in wrapped_f
retrieved = self._retrieve_data(func(self, *args))
188BET靠谱吗File "C:\Users\xxxx\miniforge3\envs\MinerU\lib\site-packages\pyzotero\zotero.py", line 403, in _retrieve_data
error_handler(self, self.request, exc)
188BET靠谱吗File "C:\Users\xxxx\miniforge3\envs\MinerU\lib\site-packages\pyzotero\zotero.py", line 1635, in error_handler
raise error_codes.get(req.status_code)(err_msg(req)) from exc
188BET靠谱吗pyzotero.zotero_errors.ResourceNotFound:
Code: 404
URL: http://localhost:23119/users/000000/items/top?limit=10&format=json
Method: GET
Response: No endpoint found
```
188BET靠谱吗Diving into the process of URL generation of pyzotero, it seems that the endpoint, path and query parameters will be parsed into different blocks and joined together (done by urllib/parser.py), and the "/api/" path is dropped.
Question:
* Did I do something wrong?
188BET靠谱吗* If directly change zotero.Zoter.endpoint is not the correct way to access local API server, is it necessary to change the internal logic of pyzotero and modify the URL generating process by myself?I don't want to fall into this situation because there are lots of URL building calls with endpoint, which means a lot of work.
* Is there any other way to make a walk-around?Like local port forwarding, etc.
Any suggestion is appreciated.
188BET靠谱吗Zotero has already set up a local API server since Zotero 7 beta 88, and the local API shares almost the same interfaces with online server API.
188BET靠谱吗I'm going to access my local zotero user library via pyzotero, and luckily found that the API endpoint in pyzotero can be accessed and set as another url base address ( 188BET靠谱吗https://github.com/urschrei/pyzotero/blob/9ca972620cd7927d9de265c1b7c3ce270e5ef9d3/src/pyzotero/zotero.py#L270).
As is shown in the local server code ( 188BET靠谱吗https://github.com/zotero/zotero/blob/main/chrome/content/zotero/xpcom/localAPI/server_localAPI.js), the local API server can be accessed at http://localhost:23119/api/.
188BET靠谱吗However, when I have set zotero.Zotero.endpoint to http:///localhost:23119/api/, the request URL is not properly generated:
```python
188BET靠谱吗from pyzotero import zotero
188BET靠谱吗zot = zotero.Zotero(ZOTERO_LIBRARY_ID, "user", ZOTERO_LOCAL_API_KEY)
zot.endpoint = " http://localhost:23119/api/"
items = zot.top(limit=10)
```
Has caused:
```
Traceback (most recent call last):
188BET靠谱吗File "C:\Users\xxxx\miniforge3\envs\MinerU\lib\site-packages\pyzotero\zotero.py", line 401, in _retrieve_data
self.request.raise_for_status()
File "C:\Users\xxxx\miniforge3\envs\MinerU\lib\site-packages\requests\models.py", line 1024, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: http://localhost:23119/users/0000000/items/top?limit=10&format=json
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "F:\paper-qa-utils\zot.py", line 9, in
items = zot.top(limit=10)
188BET靠谱吗File "C:\Users\xxxx\miniforge3\envs\MinerU\lib\site-packages\pyzotero\zotero.py", line 154, in wrapped_f
retrieved = self._retrieve_data(func(self, *args))
188BET靠谱吗File "C:\Users\xxxx\miniforge3\envs\MinerU\lib\site-packages\pyzotero\zotero.py", line 403, in _retrieve_data
error_handler(self, self.request, exc)
188BET靠谱吗File "C:\Users\xxxx\miniforge3\envs\MinerU\lib\site-packages\pyzotero\zotero.py", line 1635, in error_handler
raise error_codes.get(req.status_code)(err_msg(req)) from exc
188BET靠谱吗pyzotero.zotero_errors.ResourceNotFound:
Code: 404
URL: http://localhost:23119/users/000000/items/top?limit=10&format=json
Method: GET
Response: No endpoint found
```
188BET靠谱吗Diving into the process of URL generation of pyzotero, it seems that the endpoint, path and query parameters will be parsed into different blocks and joined together (done by urllib/parser.py), and the "/api/" path is dropped.
Question:
* Did I do something wrong?
188BET靠谱吗* If directly change zotero.Zoter.endpoint is not the correct way to access local API server, is it necessary to change the internal logic of pyzotero and modify the URL generating process by myself?I don't want to fall into this situation because there are lots of URL building calls with endpoint, which means a lot of work.
* Is there any other way to make a walk-around?Like local port forwarding, etc.
Any suggestion is appreciated.
This discussion has been closed.
188BET靠谱吗But note that if your question is specific to pyzotero, you should ask the pyzotero developer — we can't help with that.188BET靠谱吗I don't know if pyzotero has been fully updated to work with the local API.