Bug when record the binary response to yaml
Maintainer thường phản hồi trong vòng 3 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Bắt đầu với các entry point _recorder.record và _add_from_file được hiển thị trong phần tái hiện, sau đó theo dõi cách phản hồi nhị phân được ghi vào và đọc từ danbooru.yaml. Tái hiện phép so sánh quá trình tải xuống bằng hình ảnh được cung cấp và xác minh rằng tệp được mock tạo ra cùng các byte và kích thước với phản hồi ban đầu.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
When recording the binary response (e.g. image), the response is broken when added from file again.
Additional context
No response
Version of responses
0.23.3
Steps to Reproduce
Use this code to record the image's response from danbooru to danbooru.yaml
import logging
import requests
from responses import _recorder
logging.basicConfig(level=logging.DEBUG)
IMAGE_URL = 'https://cdn.donmai.us/original/e1/f8/e1f815ed0d489dddda86ac55815ce37f.jpg'
@_recorder.record(file_path='danbooru.yaml')
def main():
resp = requests.get(IMAGE_URL)
resp.raise_for_status()
if __name__ == '__main__':
main()
and then use the following code to download this image both from original danbooru site (without mocking) and from mocked responses
import logging
import os
import requests
import responses
from tqdm.auto import tqdm
logging.basicConfig(level=logging.DEBUG)
def download_file(url, filename, expected_size: int = None, desc=None, **kwargs):
session = requests.session()
response = session.get(url, stream=True, allow_redirects=True, **kwargs)
expected_size = expected_size or response.headers.get('Content-Length', None)
expected_size = int(expected_size) if expected_size is not None else expected_size
desc = desc or os.path.basename(filename)
directory = os.path.dirname(filename)
if directory:
os.makedirs(directory, exist_ok=True)
with open(filename, 'wb') as f:
with tqdm(total=expected_size, unit='B', unit_scale=True, unit_divisor=1024, desc=desc) as pbar:
for chunk in response.iter_content(chunk_size=1024):
f.write(chunk)
pbar.update(len(chunk))
actual_size = os.path.getsize(filename)
if expected_size is not None and actual_size != expected_size:
os.remove(filename)
raise requests.exceptions.HTTPError(f"Downloaded file is not of expected size, "
f"{expected_size} expected but {actual_size} found.")
return filename
responses._add_from_file('danbooru.yaml')
IMAGE_URL = 'https://cdn.donmai.us/original/e1/f8/e1f815ed0d489dddda86ac55815ce37f.jpg'
def test_danbooru_origin():
download_file(IMAGE_URL, 'test_img_actual.jpg')
@responses.activate
def test_danbooru():
download_file(IMAGE_URL, 'test_img.jpg')
if __name__ == '__main__':
test_danbooru_origin()
test_danbooru()
The you'll fine the test_img_actual.jpg is okay, its size is about 833KB.
But test_img.jpg is broken, its size is about 1.47MB.
Expected Result
The expected result of file test_img.jpg should be the same as test_img_origin.jpg.
Actual Result
And now it is broken, its size is obviously abnormal.
- Ngôn ngữ chính
- Python
- Star
- 4.3k
- Fork
- 390
- Merge trung bình
- 1 ngày 17 giờ
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của getsentry/responses
-
json_params_matcher fails on falsy top-level JSON primitives (0, False, "")Có thể đã có người làm @mayureshsonawane17 đã nhận 22 ngày trước. Đang mởWaiting for: Product Owner
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 3 ngày
-
enhancement Waiting for: Product Owner
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
getsentry/responses#783 · 1 bình luận · 3 reaction ·
Maintainer thường phản hồi trong vòng 3 ngày
-
bug Waiting for: Product Owner
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
getsentry/responses#780 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
question
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
Maintainer thường phản hồi trong vòng 3 ngày
-
Bad Network SimulationĐang mởenhancement question
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của getsentry/responses
Issue tương tự
-
parse names a key after a top-level multi() threshold Bitcoin Core v31.1 refuses as not validĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
btclib-org/btclib-wallet#587 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Judgment-Pack/judgment-pack-spec#275 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ai-generated
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation good first issue priority: low size: XS
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 92/100
yeongseon/azure-functions-doctor-python#651 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Changaco/python-libarchive-c#146 ·