Не могу получить доступ к конфигурации Spring Cloud из PythonPython

Программы на Python
Anonymous
Не могу получить доступ к конфигурации Spring Cloud из Python

Сообщение Anonymous »

Я создал сервер Spring Cloud Config (на данный момент) только с двумя файлами yaml
  • application.yml
  • application-dev.yml
Также определена Spring Security с базовой аутентификацией (имя пользователя и пароль), но, как ни странно, я не могу получить доступ к своим конфигурациям кроме браузера (Chrome и Safari).
Ниже вы можете увидеть мои конфигурации.
  • application.yml

    application.yml
# Basic configs - Name & Profile
spring:
application:
name: EMP_CNF-S
profiles:
default: ${ENVIRONMENT}

# GitHub Repository (private & SSH)
cloud:
config:
server:
git:
uri: git@github.com:*******/EMP_CNF-S.git
ignore-local-ssh-settings: true
default-label: ${ENVIRONMENT}
private-key: ${GIT_SSH_KEY}
search-paths: src/main/resources
skip-ssl-validation: true
timeout: 10
clone-on-start: true

security:
user:
name: ${EMP_CONFIG_USERNAME}
password: ${EMP_CONFIG_PASSWORD}

# Configuring Port
server:
port: 8888

# Spring Actuator
management:
endpoints:
web:
exposure:
include:
- health
- info
base-path: /actuator
endpoint:
health:
show-details: always

Вот мой application-dev.yml (все значения переменных были установлены благодаря действиям GitHub и секретам GitHub)
# Common Configurations - Datasource
spring:
datasource:
url: jdbc:mysql://localhost:3306/
username: root
password: *******

jpa:
hibernate:
ddl-auto: update
show-sql: true

test:
database:
replace: none

# Location Service
location-service:
schema: location_db

# Employee Service
employee-service:
schema: employee_db

# Customer Service
customer-service:
schema: ${EMP_SCHEMA_CUSTOMER}

# Supplier Service
supplier-service:
schema: ${EMP_SCHEMA_SUPPLIER}

Но когда я пытаюсь получить доступ к переменным среды (location_db), я не могу. Я не получаю никакого результата при попытке «свернуть» его:
curl -u admin:****** http://localhost:8888/location-service/dev

Также в моем скрипте Python при использовании модуля spring-config-client и даже с библиотекой запросов я не могу получить доступ к значениям, несмотря на получение кода успеха 200. Ниже приведен фрагмент:
import requests
from requests.auth import HTTPBasicAuth

url = "http://localhost:8888/location-service/dev"
response = requests.get(url=url, auth=HTTPBasicAuth(username='admin', password='******'), headers=headers)

# Print the raw content
print(f"Response status code: {response.status_code}")
print(f"Response text: {response.text}")

# Attempt to parse as JSON
try:
config = response.json()
print(config)
except requests.exceptions.JSONDecodeError as e:
print(f"JSON decode error: {e}")

Выход:
Response status code: 200
Response text:






Please sign in






Please sign in

Username


Password


Sign in



JSON decode error: Expecting value: line 1 column 1 (char 0)

Здесь также используется модуль spring_config:
from spring_config import ClientConfigurationBuilder
from spring_config.client import SpringConfigClient

spring_config_username = os.getenv(key = 'EMP_CONFIG_USERNAME')
spring_config_password = '****'

# Build the client configuration
config = (
ClientConfigurationBuilder()
.app_name("location-service")
.profile("dev")
.branch('dev')
.address("http://localhost:8888")
.authentication((spring_config_username, spring_config_password)) # Set the authentication
.build()
)

# Create the Spring Config Client
client = SpringConfigClient(config)

И вот вывод (ошибка):
File "/Users/acharrade/.pyenv/versions/3.12.2/lib/python3.12/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)


Подробнее здесь: https://stackoverflow.com/questions/789 ... rom-python

Вернуться в «Python»