mirror of
https://github.com/healthchecks/healthchecks.git
synced 2024-11-27 01:27:51 +00:00
b9996e63c8
HTML files in /templates/docs/ are not Django templates, they contain HTML content to be used verbatim in hc.front.views.serve_doc view. Some of these files contain "{{ ... }}" syntax. When we run "./manage.py compress", django-compressor trips up on this syntax because it treats them as Django templates. The fix is to change file extension for these files from .html to something else (I picked .html-fragment) so django-compressor would ignore them.
29 lines
2.9 KiB
Plaintext
29 lines
2.9 KiB
Plaintext
<h1>Python</h1>
|
|
<p>If you are already using the <a href="https://requests.readthedocs.io/en/master/">requests</a>
|
|
library, it is convenient to also use it here:</p>
|
|
<div class="highlight"><pre><span></span><code><span class="kn">import</span> <span class="nn">requests</span>
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="n">requests</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"PING_URL"</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="n">requests</span><span class="o">.</span><span class="n">RequestException</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="c1"># Log ping failure here...</span>
|
|
<span class="nb">print</span><span class="p">(</span><span class="s2">"Ping failed: </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="n">e</span><span class="p">)</span>
|
|
</code></pre></div>
|
|
|
|
<p>Otherwise, you can use the <a href="https://docs.python.org/3/library/urllib.request.html">urllib.request</a>
|
|
module from Python 3 standard library:</p>
|
|
<div class="highlight"><pre><span></span><code><span class="kn">import</span> <span class="nn">socket</span>
|
|
<span class="kn">import</span> <span class="nn">urllib.request</span>
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="n">urllib</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="s2">"PING_URL"</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="n">socket</span><span class="o">.</span><span class="n">error</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="c1"># Log ping failure here...</span>
|
|
<span class="nb">print</span><span class="p">(</span><span class="s2">"Ping failed: </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="n">e</span><span class="p">)</span>
|
|
</code></pre></div>
|
|
|
|
<p>You can include additional diagnostic information in the request body (for POST requests):</p>
|
|
<div class="highlight"><pre><span></span><code><span class="c1"># Passing diagnostic information in the POST body:</span>
|
|
<span class="kn">import</span> <span class="nn">requests</span>
|
|
<span class="n">requests</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="s2">"PING_URL"</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="s2">"temperature=-7"</span><span class="p">)</span>
|
|
</code></pre></div> |