-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Простейший клиент forgejo #73
base: master
Are you sure you want to change the base?
Conversation
|
||
Перед началом работы установите необходимые библиотеки: | ||
|
||
```pip install pyforgejo``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше файл requirements.txt и его устанавливать. Дополнительно лучше указывать версию используемой библиотеки
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
У меня современная macOS и такая команда заставляет не ставит пакеты
То, что у меня pip не видно глобально в расчёт не беру, а вот нет виртуального окружения (ну или на худой конец хака) -- беру :)
➜ github_repo_commitment_calc git:(master) pip3 install pyforgejo
[notice] A new release of pip is available: 24.3.1 -> 25.0.1
[notice] To update, run: python3.13 -m pip install --upgrade pip
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try brew install
xyz, where xyz is the package you are trying to
install.
If you wish to install a Python library that isn't in Homebrew,
use a virtual environment:
python3 -m venv path/to/venv
source path/to/venv/bin/activate
python3 -m pip install xyz
If you wish to install a Python application that isn't in Homebrew,
it may be easiest to use 'pipx install xyz', which will manage a
virtual environment for you. You can install pipx with
brew install pipx
You may restore the old behavior of pip by passing
the '--break-system-packages' flag to pip, or by adding
'break-system-packages = true' to your pip.conf file. The latter
will permanently disable this error.
If you disable this error, we STRONGLY recommend that you additionally
pass the '--user' flag to pip, or set 'user = true' in your pip.conf
file. Failure to do this can result in a broken Homebrew installation.
Read more about this behavior here: <https://peps.python.org/pep-0668/>
note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
В файл `token` запишите в файл API-ключ в формате: | ||
|
||
`token your_api_key_here` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Либо файл создаем сразу (как шаблон)
Либо используем .env
+load_env https://pypi.org/project/python-dotenv/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не понял откуда брать токен
API_KEY = file.read() | ||
if not API_KEY: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ну это уж не константа же)
from pyforgejo import PyforgejoApi | ||
|
||
with open('token') as file: | ||
API_KEY = file.read() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Сам запустить не смог, хотя вроде всё по инструкции делал
➜ forgejo git:(72_simple_forgejo_client) ✗ echo 'xxx' > token
➜ forgejo git:(72_simple_forgejo_client) ✗ python3 main.py
Using BASE_URL: https://codeberg.org/api/v1
Using API_KEY: ****************************************
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.13/site-packages/httpx/_transports/default.py", line 101, in map_httpcore_exceptions
yield
File "/opt/homebrew/lib/python3.13/site-packages/httpx/_transports/default.py", line 250, in handle_request
resp = self._pool.handle_request(req)
File "/opt/homebrew/lib/python3.13/site-packages/httpcore/_sync/connection_pool.py", line 256, in handle_request
raise exc from None
File "/opt/homebrew/lib/python3.13/site-packages/httpcore/_sync/connection_pool.py", line 236, in handle_request
response = connection.handle_request(
pool_request.request
)
File "/opt/homebrew/lib/python3.13/site-packages/httpcore/_sync/connection.py", line 103, in handle_request
return self._connection.handle_request(request)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
File "/opt/homebrew/lib/python3.13/site-packages/httpcore/_sync/http11.py", line 136, in handle_request
raise exc
File "/opt/homebrew/lib/python3.13/site-packages/httpcore/_sync/http11.py", line 86, in handle_request
self._send_request_headers(**kwargs)
~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
File "/opt/homebrew/lib/python3.13/site-packages/httpcore/_sync/http11.py", line 144, in _send_request_headers
with map_exceptions({h11.LocalProtocolError: LocalProtocolError}):
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.13.1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/contextlib.py", line 162, in __exit__
self.gen.throw(value)
~~~~~~~~~~~~~~^^^^^^^
File "/opt/homebrew/lib/python3.13/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
raise to_exc(exc) from exc
httpcore.LocalProtocolError: Illegal header value b'xxx\n'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/kirillkry/university/github_repo_commitment_calc/forgejo/main.py", line 11, in <module>
repo = client.repository.repo_get(owner="harabat", repo="pyforgejo")
File "/opt/homebrew/lib/python3.13/site-packages/pyforgejo/repository/client.py", line 488, in repo_get
_response = self._client_wrapper.httpx_client.request(
f"repos/{jsonable_encoder(owner)}/{jsonable_encoder(repo)}",
method="GET",
request_options=request_options,
)
File "/opt/homebrew/lib/python3.13/site-packages/pyforgejo/core/http_client.py", line 213, in request
response = self.httpx_client.request(
method=method,
...<44 lines>...
timeout=timeout,
)
File "/opt/homebrew/lib/python3.13/site-packages/httpx/_client.py", line 825, in request
return self.send(request, auth=auth, follow_redirects=follow_redirects)
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.13/site-packages/httpx/_client.py", line 914, in send
response = self._send_handling_auth(
request,
...<2 lines>...
history=[],
)
File "/opt/homebrew/lib/python3.13/site-packages/httpx/_client.py", line 942, in _send_handling_auth
response = self._send_handling_redirects(
request,
follow_redirects=follow_redirects,
history=history,
)
File "/opt/homebrew/lib/python3.13/site-packages/httpx/_client.py", line 979, in _send_handling_redirects
response = self._send_single_request(request)
File "/opt/homebrew/lib/python3.13/site-packages/httpx/_client.py", line 1014, in _send_single_request
response = transport.handle_request(request)
File "/opt/homebrew/lib/python3.13/site-packages/httpx/_transports/default.py", line 249, in handle_request
with map_httpcore_exceptions():
~~~~~~~~~~~~~~~~~~~~~~~^^
File "/opt/homebrew/Cellar/[email protected]/3.13.1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/contextlib.py", line 162, in __exit__
self.gen.throw(value)
~~~~~~~~~~~~~~^^^^^^^
File "/opt/homebrew/lib/python3.13/site-packages/httpx/_transports/default.py", line 118, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.LocalProtocolError: Illegal header value b'xxx\n'
После патча
API_KEY = file.read().strip()
Запустил)
No description provided.