python-picnic-api2 1.3.3__tar.gz → 1.3.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/PKG-INFO +1 -1
  2. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/README.md +21 -0
  3. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/pyproject.toml +1 -1
  4. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/src/python_picnic_api2/client.py +2 -2
  5. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/tests/test_client.py +5 -6
  6. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/uv.lock +1 -1
  7. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/.devcontainer/devcontainer.json +0 -0
  8. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/.env.example +0 -0
  9. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/.envrc +0 -0
  10. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
  11. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/.github/ISSUE_TEMPLATE/config.yml +0 -0
  12. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/.github/dependabot.yml +0 -0
  13. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/.github/release.yml +0 -0
  14. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/.github/workflows/ci.yaml +0 -0
  15. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/.github/workflows/it.yaml +0 -0
  16. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/.github/workflows/release.yml +0 -0
  17. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/.gitignore +0 -0
  18. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/LICENSE.md +0 -0
  19. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/README.rst +0 -0
  20. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/codecov.yml +0 -0
  21. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/flake.lock +0 -0
  22. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/flake.nix +0 -0
  23. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/integration_tests/__init__.py +0 -0
  24. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/integration_tests/test_client.py +0 -0
  25. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/integration_tests/test_helper.py +0 -0
  26. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/integration_tests/test_session.py +0 -0
  27. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/src/python_picnic_api2/__init__.py +0 -0
  28. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/src/python_picnic_api2/helper.py +0 -0
  29. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/src/python_picnic_api2/session.py +0 -0
  30. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/tests/__init__.py +0 -0
  31. {python_picnic_api2-1.3.3 → python_picnic_api2-1.3.4}/tests/test_session.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-picnic-api2
3
- Version: 1.3.3
3
+ Version: 1.3.4
4
4
  Project-URL: homepage, https://github.com/codesalatdev/python-picnic-api
5
5
  Project-URL: repository, https://github.com/codesalatdev/python-picnic-api
6
6
  Author-email: Mike Brink <mjh.brink@icloud.com>, CodeSalat <pypi@codesalat.dev>
@@ -32,6 +32,27 @@ picnic = PicnicAPI(username='username', password='password', country_code="NL")
32
32
 
33
33
  The country_code parameter defaults to `NL`, but you have to change it if you live in a different country than the Netherlands (ISO 3166-1 Alpha-2). This obviously only works for countries that picnic services.
34
34
 
35
+ ### Two-factor authentication (2FA)
36
+
37
+ For new logins, Picnic may require two-factor authentication. When 2FA is required, logging in raises a `Picnic2FARequired` exception. You then need to request a code and verify it:
38
+
39
+ ```python
40
+ from python_picnic_api2 import PicnicAPI, Picnic2FARequired, Picnic2FAError
41
+
42
+ picnic = PicnicAPI(country_code="NL")
43
+
44
+ try:
45
+ picnic.login(username='username', password='password')
46
+ except Picnic2FARequired:
47
+ # Request a code via SMS or EMAIL
48
+ picnic.generate_2fa_code(channel="SMS")
49
+
50
+ code = input("Enter the code you received: ")
51
+ picnic.verify_2fa_code(code)
52
+ ```
53
+
54
+ After successful verification, the session is authenticated and you can use the API normally. If the code is invalid, `Picnic2FAError` is raised.
55
+
35
56
  ## Searching for an article
36
57
 
37
58
  ```python
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "python-picnic-api2"
3
- version = "1.3.3"
3
+ version = "1.3.4"
4
4
  description = ""
5
5
  readme = "README.rst"
6
6
  license = {text = "Apache-2.0"}
@@ -94,8 +94,8 @@ class PicnicAPI:
94
94
  if not isinstance(response, dict):
95
95
  return False
96
96
 
97
- error_code = response.get("error", {}).get("code")
98
- return error_code == "TWO_FACTOR_AUTHENTICATION_REQUIRED"
97
+ return "second_factor_authentication_required" in response \
98
+ and response["second_factor_authentication_required"] is True
99
99
 
100
100
  def login(self, username: str, password: str):
101
101
  path = "/user/login"
@@ -343,11 +343,10 @@ class TestClient(unittest.TestCase):
343
343
 
344
344
  def test_login_requires_2fa(self):
345
345
  response = {
346
- "error": {
347
- "code": "TWO_FACTOR_AUTHENTICATION_REQUIRED",
348
- "message": "User must verify their second factor",
349
- "details": {},
350
- }
346
+ "user_id": "123-456-7890",
347
+ "second_factor_authentication_required": True,
348
+ "show_second_factor_authentication_intro": False,
349
+ "error": {},
351
350
  }
352
351
  self.session_mock().post.return_value = self.MockResponse(response, 200)
353
352
 
@@ -355,7 +354,7 @@ class TestClient(unittest.TestCase):
355
354
  with self.assertRaises(Picnic2FARequired) as ctx:
356
355
  client.login("test-user", "test-password")
357
356
  self.assertEqual(
358
- str(ctx.exception), "User must verify their second factor"
357
+ str(ctx.exception), "Two-factor authentication required"
359
358
  )
360
359
  self.assertEqual(ctx.exception.response, response)
361
360
 
@@ -146,7 +146,7 @@ wheels = [
146
146
 
147
147
  [[package]]
148
148
  name = "python-picnic-api2"
149
- version = "1.3.3"
149
+ version = "1.3.4"
150
150
  source = { editable = "." }
151
151
  dependencies = [
152
152
  { name = "requests" },