Microsoft Azure Core Library for Python
Project description
Azure Core Library
Azure core library defines basic exceptions and shared modules those are needed when you use client libraries.
As an end user, you don't need to manually install azure-core because it will be installed automatically when you install other SDKs.
If you are a client library developer, please reference client library developer reference for more information.
Source code | Package (Pypi) | API reference documentation
Azure Core Library Exceptions
AzureError
AzureError is the base exception for all errors.
class AzureError(Exception):
def __init__(self, message, *args, **kwargs):
self.inner_exception = kwargs.get('error')
self.exc_type, self.exc_value, self.exc_traceback = sys.exc_info()
self.exc_type = self.exc_type.__name__ if self.exc_type else type(self.inner_exception)
self.exc_msg = "{}, {}: {}".format(message, self.exc_type, self.exc_value) # type: ignore
self.message = str(message)
super(AzureError, self).__init__(self.message, *args)
message is any message (str) to be associated with the exception.
args are any additional args to be included with exception.
kwargs are keyword arguments to include with the exception. Use the keyword error to pass in an internal exception.
The following exceptions inherit from AzureError:
ServiceRequestError
An error occurred while attempt to make a request to the service. No request was sent.
ServiceResponseError
The request was sent, but the client failed to understand the response. The connection may have timed out. These errors can be retried for idempotent or safe operations.
HttpResponseError
A request was made, and a non-success status code was received from the service.
class HttpResponseError(AzureError):
def __init__(self, message=None, response=None, **kwargs):
self.reason = None
self.response = response
if response:
self.reason = response.reason
message = "Operation returned an invalid status code '{}'".format(self.reason)
try:
try:
if self.error.error.code or self.error.error.message:
message = "({}) {}".format(
self.error.error.code,
self.error.error.message)
except AttributeError:
if self.error.message: #pylint: disable=no-member
message = self.error.message #pylint: disable=no-member
except AttributeError:
pass
super(HttpResponseError, self).__init__(message=message, **kwargs)
message is the HTTP response error message (optional)
response is the HTTP response (optional).
kwargs are keyword arguments to include with the exception.
The following exceptions inherit from HttpResponseError:
DecodeError
An error raised during response deserialization.
ResourceExistsError
An error response with status code 4xx. This will not be raised directly by the Azure core pipeline.
ResourceNotFoundError
An error response, typically triggered by a 412 response (for update) or 404 (for get/post).
ClientAuthenticationError
An error response with status code 4xx. This will not be raised directly by the Azure core pipeline.
ResourceModifiedError
An error response with status code 4xx, typically 412 Conflict. This will not be raised directly by the Azure core pipeline.
ResourceNotModifiedError
An error response with status code 304. This will not be raised directly by the Azure core pipeline.
TooManyRedirectsError
An error raised when the maximum number of redirect attempts is reached. The maximum amount of redirects can be configured in the RedirectPolicy.
class TooManyRedirectsError(HttpResponseError):
def __init__(self, history, *args, **kwargs):
self.history = history
message = "Reached maximum redirect attempts."
super(TooManyRedirectsError, self).__init__(message, *args, **kwargs)
history is used to document the requests/responses that resulted in redirected requests.
args are any additional args to be included with exception.
kwargs are keyword arguments to include with the exception.
Shared modules
MatchConditions
MatchConditions is an enum to describe match conditions.
class MatchConditions(Enum):
Unconditionally = 1
IfNotModified = 2
IfModified = 3
IfPresent = 4
IfMissing = 5
Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
Release History
1.3.0 (2020-03-09)
Bug fixes
- Appended RequestIdPolicy to the default pipeline #9841
- Rewind the body position in async_retry #10117
Features
- Add raw_request_hook support in custom_hook_policy #9958
- Add timeout support in retry_policy #10011
- Add OdataV4 error format auto-parsing in all exceptions ('error' attribute) #9738
1.2.2 (2020-02-10)
Bug fixes
- Fixed a bug that sends None as request_id #9545
- Enable mypy for customers #9572
- Handle TypeError in deep copy #9620
- Fix text/plain content-type in decoder #9589
1.2.1 (2020-01-14)
Bug fixes
- Fixed a regression in 1.2.0 that was incompatible with azure-keyvault-* 4.0.0 #9462
1.2.0 (2020-01-14)
Features
- Add user_agent & sdk_moniker kwargs in UserAgentPolicy init #9355
- Support OPTIONS HTTP verb #9322
- Add tracing_attributes to tracing decorator #9297
- Support auto_request_id in RequestIdPolicy #9163
- Support fixed retry #6419
- Support "retry-after-ms" in response header #9240
Bug fixes
- Removed
__enter__and__exit__from async context managers #9313
1.1.1 (2019-12-03)
Bug fixes
- Bearer token authorization requires HTTPS
- Rewind the body position in retry #8307
1.1.0 (2019-11-25)
Features
- New RequestIdPolicy #8437
- Enable logging policy in default pipeline #8053
- Normalize transport timeout. #8000
Now we have:
- 'connection_timeout' - a single float in seconds for the connection timeout. Default 5min
- 'read_timeout' - a single float in seconds for the read timeout. Default 5min
Bug fixes
- RequestHistory: deepcopy fails if request contains a stream #7732
- Retry: retry raises error if response does not have http_response #8629
- Client kwargs are now passed to DistributedTracingPolicy correctly #8051
- NetworkLoggingPolicy now logs correctly all requests in case of retry #8262
1.0.0 (2019-10-29)
Features
- Tracing: DistributedTracingPolicy now accepts kwargs network_span_namer to change network span name #7773
- Tracing: Implementation of AbstractSpan can now use the mixin HttpSpanMixin to get HTTP span update automatically #7773
- Tracing: AbstractSpan contract "change_context" introduced #7773
- Introduce new policy HttpLoggingPolicy #7988
Bug fixes
- Fix AsyncioRequestsTransport if input stream is an async generator #7743
- Fix form-data with aiohttp transport #7749
Breaking changes
- Tracing: AbstractSpan.set_current_span is longer supported. Use change_context instead. #7773
- azure.core.pipeline.policies.ContentDecodePolicy.deserialize_from_text changed
1.0.0b4 (2019-10-07)
Features
-
Tracing: network span context is available with the TRACING_CONTEXT in pipeline response #7252
-
Tracing: Span contract now has
kind,traceparentand is a context manager #7252 -
SansIOHTTPPolicy methods can now be coroutines #7497
-
Add multipart/mixed support #7083:
- HttpRequest now has a "set_multipart_mixed" method to set the parts of this request
- HttpRequest now has a "prepare_multipart_body" method to build final body.
- HttpResponse now has a "parts" method to return an iterator of parts
- AsyncHttpResponse now has a "parts" methods to return an async iterator of parts
- Note that multipart/mixed is a Python 3.x only feature
Bug fixes
- Tracing: policy cannot fail the pipeline, even in the worst condition #7252
- Tracing: policy pass correctly status message if exception #7252
- Tracing: incorrect span if exception raised from decorated function #7133
- Fixed urllib3 ConnectTimeoutError being raised by Requests during a socket timeout. Now this exception is caught and wrapped as a
ServiceRequestError#7542
Breaking changes
-
Tracing:
azure.core.tracing.contextremoved -
Tracing:
azure.core.tracing.context.tracing_context.with_current_contextrenamed toazure.core.tracing.common.with_current_context#7252 -
Tracing:
linkrenamedlink_from_headersandlinktakes now a string -
Tracing: opencensus implementation has been moved to the package
azure-core-tracing-opencensus -
Some modules and classes that were importables from several differente places have been removed:
azure.core.HttpResponseErroris now onlyazure.core.exceptions.HttpResponseErrorazure.core.Configurationis now onlyazure.core.configuration.Configurationazure.core.HttpRequestis now onlyazure.core.pipeline.transport.HttpRequestazure.core.versionmodule has been removed. Useazure.core.__version__to get version number.azure.core.pipeline_clienthas been removed. Import fromazure.coreinstead.azure.core.pipeline_client_asynchas been removed. Import fromazure.coreinstead.azure.core.pipeline.basehas been removed. Import fromazure.core.pipelineinstead.azure.core.pipeline.base_asynchas been removed. Import fromazure.core.pipelineinstead.azure.core.pipeline.policies.basehas been removed. Import fromazure.core.pipeline.policiesinstead.azure.core.pipeline.policies.base_asynchas been removed. Import fromazure.core.pipeline.policiesinstead.azure.core.pipeline.policies.authenticationhas been removed. Import fromazure.core.pipeline.policiesinstead.azure.core.pipeline.policies.authentication_asynchas been removed. Import fromazure.core.pipeline.policiesinstead.azure.core.pipeline.policies.custom_hookhas been removed. Import fromazure.core.pipeline.policiesinstead.azure.core.pipeline.policies.redirecthas been removed. Import fromazure.core.pipeline.policiesinstead.azure.core.pipeline.policies.redirect_asynchas been removed. Import fromazure.core.pipeline.policiesinstead.azure.core.pipeline.policies.retryhas been removed. Import fromazure.core.pipeline.policiesinstead.azure.core.pipeline.policies.retry_asynchas been removed. Import fromazure.core.pipeline.policiesinstead.azure.core.pipeline.policies.distributed_tracinghas been removed. Import fromazure.core.pipeline.policiesinstead.azure.core.pipeline.policies.universalhas been removed. Import fromazure.core.pipeline.policiesinstead.azure.core.tracing.abstract_spanhas been removed. Import fromazure.core.tracinginstead.azure.core.pipeline.transport.basehas been removed. Import fromazure.core.pipeline.transportinstead.azure.core.pipeline.transport.base_asynchas been removed. Import fromazure.core.pipeline.transportinstead.azure.core.pipeline.transport.requests_basichas been removed. Import fromazure.core.pipeline.transportinstead.azure.core.pipeline.transport.requests_asynciohas been removed. Import fromazure.core.pipeline.transportinstead.azure.core.pipeline.transport.requests_triohas been removed. Import fromazure.core.pipeline.transportinstead.azure.core.pipeline.transport.aiohttphas been removed. Import fromazure.core.pipeline.transportinstead.azure.core.polling.pollerhas been removed. Import fromazure.core.pollinginstead.azure.core.polling.async_pollerhas been removed. Import fromazure.core.pollinginstead.
1.0.0b3 (2019-09-09)
Bug fixes
- Fix aiohttp auto-headers #6992
- Add tracing to policies module init #6951
1.0.0b2 (2019-08-05)
Breaking changes
- Transport classes don't take
configparameter anymore (use kwargs instead) #6372 azure.core.paginghas been completely refactored #6420- HttpResponse.content_type attribute is now a string (was a list) #6490
- For
StreamDownloadGeneratorsubclasses,responseis now anHttpResponse, and not a transport response likeaiohttp.ClientResponseorrequests.Response. The transport response is available ininternal_responseattribute #6490
Bug fixes
- aiohttp is not required to import async pipelines classes #6496
AsyncioRequestsTransport.sleepis now a coroutine as expected #6490RequestsTransportis not tight toProxyPolicyimplementation details anymore #6372AiohttpTransportdoes not raise on unexpected kwargs #6355
Features
- New paging base classes that support
continuation_tokenandby_page()#6420 - Proxy support for
AiohttpTransport#6372
1.0.0b1 (2019-06-26)
- Preview 1 release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file azure-core-1.3.0.zip.
File metadata
- Download URL: azure-core-1.3.0.zip
- Upload date:
- Size: 180.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98d03a35845fe5b6abaa32f5961214da3e16c4c82b8c601926fc5e7f3a39549e
|
|
| MD5 |
386817113df91135863b410344ae5d22
|
|
| BLAKE2b-256 |
7a7d761ab78f84df45d89c2bcb4357ae4d06703a249771c1121b97a7eadf820d
|
File details
Details for the file azure_core-1.3.0-py2.py3-none-any.whl.
File metadata
- Download URL: azure_core-1.3.0-py2.py3-none-any.whl
- Upload date:
- Size: 106.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e0ab27318023cee172063569b91ff4ee1c1d9d74ab2dae642b5f24c9c991edc
|
|
| MD5 |
5d0ecd41cd348888f5069d75173f9ac4
|
|
| BLAKE2b-256 |
41ed3fe8be1f383bdaea4329462f5b2215785090547ac439965c48e814b8f02e
|