Can’t access Spring Cloud Config from Python

I’ve created a Spring Cloud Config Server with (for now) only two yaml files

  • application.yml
  • application-dev.yml

Also Spring Security with basic authentication (username & password) is defined, but curiously I can’t access my configurations except from browser (Chrome & Safari).

Below you can see my configurations.

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

# GitHub Repository (private & SSH)
    cloud:
        config:
            server:
                git:
                    uri: [email protected]:*******/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

Here my application-dev.yml (Every variable value was set due to GitHub Actions & GitHub Secrets)

# 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}

But when I try to access my environment variables (location_db) I can’t. I do get no result when trying to “curl” it:

curl -u admin:****** http://localhost:8888/location-service/dev

Also in my python script when using module spring-config-client and even with requests library I can’t access the values despite getting a 200 success code. Here a snippet below:

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}")

Output:

Response status code: 200
Response text: <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>Please sign in</title>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
    <link href="https://getbootstrap.com/docs/4.0/examples/signin/signin.css" rel="stylesheet" integrity="sha384-oOE/3m0LUMPub4kaC09mrdEhIc+e3exm4xOGxAmuFXhBNF4hcg/6MiAXAf5p0P56" crossorigin="anonymous"/>
  </head>
  <body>
     <div class="container">
      <form class="form-signin" method="post" action="/login">
        <h2 class="form-signin-heading">Please sign in</h2>
        <p>
          <label for="username" class="sr-only">Username</label>
          <input type="text" id="username" name="username" class="form-control" placeholder="Username" required autofocus>
        </p>
        <p>
          <label for="password" class="sr-only">Password</label>
          <input type="password" id="password" name="password" class="form-control" placeholder="Password" required>
        </p>
        <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
      </form>
</div>
</body></html>
JSON decode error: Expecting value: line 1 column 1 (char 0)

Here also the usage of spring_config module:

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)

And here the (error) output:

  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)

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật