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
Switch to depend on requests library #129
Comments
What do you think @graingert @elidickinson @ionelmc ? |
python3 doesn't have requests built in. |
So that was just a rumor I heard then. Well, it makes it easier to just depend on the new external dependency. |
I think you should go for something like http://weasyprint.org/docs/tutorial/#url-fetchers |
Interesting but I'm not sure I follow. How is that better/different than |
Their default implementation looks pretty robust: And users of this library can override it as they see fit. Eg for my site I checked for def my_fetcher(url):
if url.stats_with('/static/'):
return django_static_file_finder(urlparse(url).path)
else:
return weasyprint.default_url_fetcher(url)
weasyprint.HTML(doc, url_fetcher=my_fetcher) |
You could also create a requests implementation: try:
import requests
except ImportError:
def _default_url_fetcher(url):
...
else:
def _default_url_fetcher(url):
...
fileobj = session.get(url, stream=True).raw
...
# For autocomplete and static analysis etc
def default_url_fetcher(url):
return _default_url_fetcher(url)
def premailer(doc, url_fetcher=default_url_fetcher):
... |
I'd also add an argument in for a HTTP 'Accept' header so for: <link rel="stylesheet" type="text/css" href="https://example.com/theme.css"> You'd call: default_url_fetcher(url='https://example.com/theme.css', mimetype='text/css') |
I think it's fine having some |
But why do you need all of that? What's wrong with simply doing |
Accept header is nothing to do with gzip. The servers can return different documents depending on the Accept header |
But is that likely? Have you had problems with doing (Sorry if I sound like I'm "fighting". I'm just trying to learn. And keep things simple :) at the same time) |
It's just part of the http spec. I've seen some sites render their entire page off of '/' using the accept header |
Haha! Well, they're nuts! :) |
What was the consensus on this? |
My view is that anything overly complex is going to mean more code to maintain. A switch to relying on |
I just ran into this bug today. This is the error when using an SSL url for the css file. The only fix I could find was to not use ssl on the url which makes configuring my app harder because all other pages, files, etc need ssl.
|
@alexphelps I bet if you take that same URL (the https one) and try to do |
@peterbe: I think this issue can be closed. |
I have had more than one problem with the built-in
urlopen()
to download certain URLs.This one for example fails on some SSL trouble in
urlopen
but opens nicely withrequests
from my OSX laptop.I thought Python 3 was supposed to have
requests
built in so maybe this is only necessary for Python 2.The text was updated successfully, but these errors were encountered: