From 851772a1163faa4c4e3f0c217f17a8dd8d39aa60 Mon Sep 17 00:00:00 2001 From: docentYT <63965954+docentYT@users.noreply.github.com> Date: Wed, 26 Jul 2023 13:04:15 +0200 Subject: [PATCH] Fix problems with latin-1 codec. --- CHANGELOG.md | 4 ++++ src/osm_easy_api/__init__.py | 2 +- src/osm_easy_api/api/api.py | 2 +- tests/api/test_api.py | 14 +++++++++++++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f754e51..e68831a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.0.2] +### Fixed +- Auth problems in API when using characters unsupported by latin-1 codec. + ## [1.0.1] ### Fixed - `api.notes.create()` created only anonymous notes. diff --git a/src/osm_easy_api/__init__.py b/src/osm_easy_api/__init__.py index 0f1afbd..a772546 100644 --- a/src/osm_easy_api/__init__.py +++ b/src/osm_easy_api/__init__.py @@ -1,4 +1,4 @@ -VERSION = "1.0.1" +VERSION = "1.0.2" from .data_classes import * from .diff import Diff, Frequency diff --git a/src/osm_easy_api/api/api.py b/src/osm_easy_api/api/api.py index 250a3a1..e74e8a4 100644 --- a/src/osm_easy_api/api/api.py +++ b/src/osm_easy_api/api/api.py @@ -37,7 +37,7 @@ def __init__(self, url: str = "https://master.apis.dev.openstreetmap.org", usern self.notes = Notes_Container(self) if username and password: - self._auth = HTTPBasicAuth(username, password) + self._auth = HTTPBasicAuth(username.encode('utf-8'), password.encode('utf-8')) else: self._auth = None diff --git a/tests/api/test_api.py b/tests/api/test_api.py index 4b5743b..229ad10 100644 --- a/tests/api/test_api.py +++ b/tests/api/test_api.py @@ -3,4 +3,16 @@ from osm_easy_api import Api class TestApi(unittest.TestCase): - api = Api("https://test.pl") \ No newline at end of file + def test_initialize(self): + Api("https://test.pl") + + def test_credintials(self): + api = Api(username="abc", password="cba") + self.assertIsNotNone(api._auth) + self.assertEqual(api._auth.username.decode(), "abc") + self.assertEqual(api._auth.password.decode(), "cba") + + api = Api(username="ęśąćź", password="ąęźż") + self.assertIsNotNone(api._auth) + self.assertEqual(api._auth.username.decode(), "ęśąćź") + self.assertEqual(api._auth.password.decode(), "ąęźż") \ No newline at end of file