v3.0.0 Beta #116
Replies: 14 comments 44 replies
-
This check is wrong and is throwing an error if zone ID is specified but NOT account ID. In fact I think it throws an error on ANY combination of account ID and zone ID being set or not set. :) Did a PR: |
Beta Was this translation helpful? Give feedback.
-
Hello, I am just migrating a very simple script from v2 to v3: the script iterates over all email routing rules in one specific zone and changes the destination address by updating the existing rule. I am unable to get pagination working as expected. Currently, only the first and second page are processed, but there are four pages. There are 77 rules, each page returns 20 of those.
The script is pretty simple, here it is. from pprint import pprint
import cloudflare
from cloudflare import Cloudflare
from cloudflare.types.email_routing import ActionParam, MatcherParam
def main():
token = "REMOVED"
client = Cloudflare(api_token=token)
zone_id = "REMOVED"
current_email_address = "REMOVED"
new_email_address = "REMOVED"
for email_route in client.email_routing.rules.list(zone_identifier=zone_id):
pprint("old rule")
pprint(email_route)
if (
email_route.id
and email_route.actions
and len(email_route.actions) == 1
and email_route.actions[0].type == "forward"
and len(email_route.actions[0].value) == 1
and email_route.actions[0].value[0] == current_email_address
and email_route.matchers
and len(email_route.matchers) == 1
and email_route.matchers[0].type == "literal"
and email_route.matchers[0].field == "to"
):
try:
new_email_route = client.email_routing.rules.update(
rule_identifier=email_route.id,
zone_identifier=zone_id,
actions=[ActionParam(type="forward", value=[new_email_address])],
matchers=[
MatcherParam(
field="to",
type="literal",
value=email_route.matchers[0].value,
)
],
)
pprint("new rule")
pprint(new_email_route)
except cloudflare.APIError as e:
exit(e.message)
if __name__ == "__main__":
main() Here is the debug output.
As you can see, only the first and second page are fetched ( The README has the following sentence and the example is similar to my code.
Am I using the library wrong or is there a problem with the example in the README? Any help would be appreciated. Kind regards, Markus |
Beta Was this translation helpful? Give feedback.
-
Looking for command |
Beta Was this translation helpful? Give feedback.
-
I am struggling with the usability of this library for updating things. For example I want to add an email address to an access group (example below). Is this the right way? Do I have to specify all the parameters to update() individually? Is there a way to just pass the whole group back in?
|
Beta Was this translation helpful? Give feedback.
-
I was running through the testsuite for version 3.0.1 with python 3.11 and python 3.12 and tests/test_client.py::TestAsyncCloudflare::test_copy_build_request intermittently fails |
Beta Was this translation helpful? Give feedback.
-
I notice that the create test for the Images API is marked as broken in the tests: https://github.com/cloudflare/cloudflare-python/blob/main/tests/api_resources/images/test_v1.py#L25 I've been trying to upload images for a bit, and it seems like the API is expecting a multipart/form-data for the file contents (In cases where you're sending a file), but the client is sending it all as JSON, causing an error 5415 ("Must be uploaded as a form, not as raw image data. Please use multipart/form-data format"). Is there an estimated timeline for this to be fixed? |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm having some trouble pulling a zone inventory using the 3.x SDK, the setting types id doesn't work as expected and I wasn't able to figure out why. I was looking at this part of the documentation related to zones settings. Here's an example of code that will fail with an from cloudflare import Cloudflare, CloudflareError
from cloudflare.types.zones import (
WAF,
SettingGetResponse
)
client = Cloudflare(
api_token=<API_TOKEN>,
)
zones = client.zones.list()
inventory = []
for zone in zones:
inventory.append(
{
"name": zone.name,
"status": zone.status,
"id": zone.id,
"owner": zone.owner.to_dict(),
"meta": zone.meta.to_dict(),
# Fails unless I pass the string "waf" as a positional argument
"waf_setting": client.zones.settings.get(WAF.id, zone_id=zone.id),
# I kind of expected this to fail but still curious if this is something you can handle
"settings": client.zones.settings.get(SettingGetResponse.id, zone_id=zone.id),
}
) FWIW I'm interested in pulling for each zone the WAF settings (on/off) and the rules enabled and the same for the Bot Control settings and DDoS settings among other things, if you could tell me the best approach to get there that'd be great too. Navigating through the SDK API documentation could be easier with a table of content, if that's something you could add too. Thanks |
Beta Was this translation helpful? Give feedback.
-
I have noticed that the new version 3.0 has significant longer import time. Is it something expected? I am testing it on a raspberry pi 4 by the way.
|
Beta Was this translation helpful? Give feedback.
-
Ya, it is much faster now. Before
After
Note that it is running on a raspberry pi 4, so it is expected to be slower. |
Beta Was this translation helpful? Give feedback.
-
I'm unable to update rulesets current_rule = cf.rulesets.phases.get("http_request_firewall_managed", zone_id=zone_id)
for rule in current_rule.rules:
if isinstance(rule, ExecuteRule) and rule.action_parameters.id == CLOUDFLARE_OWASP_RULESET:
# Mutate
break
cf.rulesets.phases.update("http_request_firewall_managed", rules=current_rule.rules, zone_id=zone_id) Result: Calling Package cloudflare version 3.1.0 |
Beta Was this translation helpful? Give feedback.
-
I cannot create a ratelimit rule because the parameter does not have a ratelimit option,Package cloudflare version 3.1.0 |
Beta Was this translation helpful? Give feedback.
-
A fresh venv running cloudflare sdk is not working. pydantic throws an error on import. |
Beta Was this translation helpful? Give feedback.
-
Forward annotations issues with Pydantic 2.10A pretty obscure issue is happening right now with Pydantic 2.10. This is due to the internal implementation of the
Edit: Just noticed that @RobertCraigie you are part of the Stainless API team. Let me know if you need more details on how to work this out together. Technical details of the issueIn the automatically generated types of the Python cloudflare SDK, you are making use of type aliases and the old cloudflare-python/src/cloudflare/types/request_tracers/trace.py Lines 3 to 11 in 7d935bd When using Now coming back to the SDK, the # Original source code: https://github.com/cloudflare/cloudflare-python/blob/7d935b/src/cloudflare/types/request_tracers/trace_item.py#L44-L47
from .trace import Trace
# At this point, `Trace` is equal to `List[ForwardRef('TraceItem')]`, but the ForwardRef instance
# inside the List doesn't have the cached evaluated value
if PYDANTIC_V2:
TraceItem.model_rebuild()
# Because 'TraceItem' is available here when calling model_rebuild(), the ForwardRef instance
# now has the cached value saved for future reuse. Then, the And the following happens:
Potential fixesIn general, it is best to avoid using aliases with forward references. Consider the following example: # module1.py
from typing import List
Alias = List['SomeType']
SomeType = int
# module2.py
from module1 import Alias
from pydantic import BaseModel
class Model(BaseModel):
a: Alias At runtime, from module1 import Alias
from pydantic import BaseModel
class Model(BaseModel):
a: List['SomeType'] because # module1.py
from typing import List
from typing_extensions import TypeAliasType
Alias = TypeAliasType('Alias', List['SomeType'])
SomeType = int
# module2.py
from module1 import Alias
from pydantic import BaseModel
class Model(BaseModel):
a: Alias |
Beta Was this translation helpful? Give feedback.
-
With the release of httpx 0.28.0 this library fails with:
Which I assume is due to the removal of the proxies argument which has been deprecated prior to this https://github.com/encode/httpx/releases/tag/0.28.0 |
Beta Was this translation helpful? Give feedback.
-
Warning
v3.x
of this library is a ground-up rewrite of the SDK, using code generation from our OpenAPI spec.This package should be in a usable state for many projects, but expect frequent minor breaking
changes as we rename methods and types until GA. If this isn't suitable for you project, we recommend
pinning to the
2.x
releases for now.We're working on a new major version of our SDK and are excited to have you test it!
Please use this discussion page as a place to report issues and feedback about the new release.
Install
Important
You may need to uninstall the package if you've installed it previously due to how
pip
handles linking.Things we would like feedback on
Beta Was this translation helpful? Give feedback.
All reactions