nonecap 0.6.2__tar.gz → 0.7.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: nonecap
3
- Version: 0.6.2
3
+ Version: 0.7.0
4
4
  Summary: Official Python client for the NoneCap hCaptcha solving API.
5
5
  Project-URL: Homepage, https://nonecap.com
6
6
  Project-URL: Documentation, https://nonecap.com/api-reference
@@ -67,6 +67,7 @@ solve = nc.solve(
67
67
 
68
68
  print(solve.token) # the hCaptcha token, ready to submit
69
69
  print(solve.resp_key) # hcaptcha.getRespKey() equivalent, for sites that verify the pair
70
+ print(solve.user_agent) # submit the token with this User-Agent: some sites check the browser version
70
71
  ```
71
72
 
72
73
  `solve()` submits the captcha and waits until it's done, using the API's long-poll so you aren't hammering it with requests. It returns the solved solve, or raises if the solve fails or your timeout runs out.
@@ -36,6 +36,7 @@ solve = nc.solve(
36
36
 
37
37
  print(solve.token) # the hCaptcha token, ready to submit
38
38
  print(solve.resp_key) # hcaptcha.getRespKey() equivalent, for sites that verify the pair
39
+ print(solve.user_agent) # submit the token with this User-Agent: some sites check the browser version
39
40
  ```
40
41
 
41
42
  `solve()` submits the captcha and waits until it's done, using the API's long-poll so you aren't hammering it with requests. It returns the solved solve, or raises if the solve fails or your timeout runs out.
@@ -110,6 +110,11 @@ class Solve:
110
110
  """Milliseconds the solve waited in the queue before a worker picked it up."""
111
111
  resolve_ms: Optional[int]
112
112
  """Milliseconds of actual solving."""
113
+ user_agent: Optional[str] = None
114
+ """The browser user agent the solve presented while it earned ``token``. Some sites
115
+ reject a token submitted by a different browser version, so send the token with this
116
+ as your ``User-Agent`` header (and from the same IP as your proxy, if you gave one).
117
+ Set alongside ``token``, otherwise None."""
113
118
 
114
119
  @property
115
120
  def is_terminal(self) -> bool:
@@ -144,6 +149,7 @@ class Solve:
144
149
  finished_at=data.get("finished_at"),
145
150
  queue_ms=data.get("queue_ms"),
146
151
  resolve_ms=data.get("resolve_ms"),
152
+ user_agent=data.get("user_agent"),
147
153
  )
148
154
 
149
155
 
@@ -0,0 +1 @@
1
+ __version__ = "0.7.0"
@@ -45,6 +45,7 @@ def solve_payload(**overrides: Any) -> dict[str, Any]:
45
45
  "url": "https://example.com",
46
46
  "token": None,
47
47
  "resp_key": None,
48
+ "user_agent": None,
48
49
  "error": None,
49
50
  "credits_charged": None,
50
51
  "proxy_bytes": None,
@@ -66,6 +66,23 @@ class TestRetrieve:
66
66
  nc = client_for(script)
67
67
  assert nc.solves.retrieve("solve_1").resp_key is None
68
68
 
69
+ def test_returns_the_user_agent_the_solve_presented(self) -> None:
70
+ ua = (
71
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
72
+ " (KHTML, like Gecko) Chrome/152.0.0.0 Safari/537.36"
73
+ )
74
+ script = Script((200, solve_payload(status="solved", token="P1_tok", user_agent=ua)))
75
+ nc = client_for(script)
76
+ assert nc.solves.retrieve("solve_1").user_agent == ua
77
+
78
+ def test_user_agent_is_none_until_solved_or_when_absent(self) -> None:
79
+ nc = client_for(Script((200, solve_payload())))
80
+ assert nc.solves.retrieve("solve_1").user_agent is None
81
+ payload = solve_payload(status="solved", token="P1_tok")
82
+ del payload["user_agent"]
83
+ nc = client_for(Script((200, payload)))
84
+ assert nc.solves.retrieve("solve_1").user_agent is None
85
+
69
86
 
70
87
  class TestCreate:
71
88
  def test_posts_with_bearer_auth_and_json_body(self) -> None:
@@ -1 +0,0 @@
1
- __version__ = "0.6.2"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes