Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout for default_url_fetcher #306

Closed
PAStheLoD opened this issue Mar 16, 2016 · 4 comments
Closed

Timeout for default_url_fetcher #306

PAStheLoD opened this issue Mar 16, 2016 · 4 comments
Labels
feature New feature that should be supported
Milestone

Comments

@PAStheLoD
Copy link

Hello!

In some cases slow external assets can basically lock up WeasyPrint, because currently no timeout is given to Requests. Maybe a default value of 30 seconds is reasonable, though making it user configurable would be better.

Thanks!

@liZe liZe added the feature New feature that should be supported label Mar 16, 2016
@liZe liZe changed the title Feature request: timeout for default_url_fetcher Timeout for default_url_fetcher Mar 16, 2016
@SimonSapin
Copy link
Member

WeasyPrint uses urllib2 / urllib.request, not Requests. The urlopen function has had an optional timeout parameter since Python 2.6, so it shouldn’t be hard to use that. What should this look like in WeasyPrint’s Python API? Something like this?

weasyprint.HTML(…, url_fetcher=weasyprint.default_url_fetcher.with_timeout(30))

@PAStheLoD
Copy link
Author

I had a global setting in mind, sort of

import weasyprint
weasyprint.URL_FETCHER_TIMEOUT = 30.0

But the .with_timeout(30) provides call site customizability.

I tried to chase the type of the timeout argument, but let's just say that urllib is not the most elegant piece of code I've seen, so going the empirical way it seems it accepts and respects floats.

@SimonSapin
Copy link
Member

Docs say

The optional timeout parameter specifies a timeout in seconds for blocking operations like the connection attempt (if not specified, the global default timeout setting will be used).

I’m fairly sure both integers and float arguments work.

If you want a global setting, it sounds like socket.setdefaulttimeout() would work without any change to WeasyPrint.

@yardensachs
Copy link

+1
Recent S3 issue, made the generation of PDF a failure because S3 did not return the images.

I would like to change the timeout for PDF files without changing the timeout for all sockets.

@liZe liZe added this to the 43 milestone Mar 7, 2018
@liZe liZe closed this as completed in 5807f18 Mar 7, 2018
netbsd-srcmastr referenced this issue in NetBSD/pkgsrc Nov 14, 2018
Version 43
----------

Released on 2018-11-09.

Bug fixes:

* `#726 <https://github.com/Kozea/WeasyPrint/issues/726>`_:
  Make empty strings clear previous values of named strings
* `#729 <https://github.com/Kozea/WeasyPrint/issues/729>`_:
  Include tools in packaging

This version also includes the changes from unstable rc1 and rc2 versions
listed below.

Version 43rc2
-------------

Released on 2018-11-02.

**This version is experimental, don't use it in production. If you find bugs,
please report them!**

Bug fixes:

* `#706 <https://github.com/Kozea/WeasyPrint/issues/706>`_:
  Fix text-indent at the beginning of a page
* `#687 <https://github.com/Kozea/WeasyPrint/issues/687>`_:
  Allow query strings in file:// URIs
* `#720 <https://github.com/Kozea/WeasyPrint/issues/720>`_:
  Optimize minimum size calculation of long inline elements
* `#717 <https://github.com/Kozea/WeasyPrint/issues/717>`_:
  Display <details> tags as blocks
* `#691 <https://github.com/Kozea/WeasyPrint/issues/691>`_:
  Don't recalculate max content widths when distributing extra space for tables
* `#722 <https://github.com/Kozea/WeasyPrint/issues/722>`_:
  Fix bookmarks and strings set on images
* `#723 <https://github.com/Kozea/WeasyPrint/issues/723>`_:
  Warn users when string() is not used in page margin


Version 43rc1
-------------

Released on 2018-10-15.

**This version is experimental, don't use it in production. If you find bugs,
please report them!**

Dependencies:

* Python 3.4+ is now needed, Python 2.x is not supported anymore
* Cairo 1.15.4+ is now needed, but 1.10+ should work with missing features
  (such as links, outlines and metadata)
* Pdfrw is not needed anymore

New features:

* `Beautiful website <https://weasyprint.org>`_
* `#579 <https://github.com/Kozea/WeasyPrint/issues/579>`_:
  Initial support of flexbox
* `#592 <https://github.com/Kozea/WeasyPrint/pull/592>`_:
  Support @font-face on Windows
* `#306 <https://github.com/Kozea/WeasyPrint/issues/306>`_:
  Add a timeout parameter to the URL fetcher functions
* `#594 <https://github.com/Kozea/WeasyPrint/pull/594>`_:
  Split tests using modern pytest features
* `#599 <https://github.com/Kozea/WeasyPrint/pull/599>`_:
  Make tests pass on Windows
* `#604 <https://github.com/Kozea/WeasyPrint/pull/604>`_:
  Handle target counters and target texts
* `#631 <https://github.com/Kozea/WeasyPrint/pull/631>`_:
  Enable counter-increment and counter-reset in page context
* `#622 <https://github.com/Kozea/WeasyPrint/issues/622>`_:
  Allow pathlib.Path objects for HTML, CSS and Attachment classes
* `#674 <https://github.com/Kozea/WeasyPrint/issues/674>`_:
  Add extensive installation instructions for Windows

Bug fixes:

* `#558 <https://github.com/Kozea/WeasyPrint/issues/558>`_:
  Fix attachments
* `#565 <https://github.com/Kozea/WeasyPrint/issues/565>`_,
  `#596 <https://github.com/Kozea/WeasyPrint/issues/596>`_,
  `#539 <https://github.com/Kozea/WeasyPrint/issues/539>`_:
  Fix many PDF rendering, printing and compatibility problems
* `#614 <https://github.com/Kozea/WeasyPrint/issues/614>`_:
  Avoid crashes and endless loops caused by a Pango bug
* `#662 <https://github.com/Kozea/WeasyPrint/pull/662>`_:
  Fix warnings and errors when generating documentation
* `#666 <https://github.com/Kozea/WeasyPrint/issues/666>`_,
  `#685 <https://github.com/Kozea/WeasyPrint/issues/685>`_:
  Fix many table layout rendering problems
* `#680 <https://github.com/Kozea/WeasyPrint/pull/680>`_:
  Don't crash when there's no font available
* `#662 <https://github.com/Kozea/WeasyPrint/pull/662>`_:
  Fix support of some align values in tables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature that should be supported
Projects
None yet
Development

No branches or pull requests

4 participants