title: python 3.x urllib.request.HTTPSHandler override METHOD GET POST
body: <pre><code>context = ssl.create_default_context()
  context.load_cert_chain(certificate, pkey)
  opener = urllib.request.build_opener(urllib.request.HTTPSHandler(context=context))
  response = opener.open(url, data=None)
  print(response.read())
  </code></pre>
  <p>Executing the above code with data=None automatically sets the METHOD to GET, while setting data to anything else automatically sets the METHOD to POST.</p>
  <p>Is there a way to override this behavior?</p>
  <p>According to the docs you can use Request.method, but I'm not understanding how to reference that from 'opener'.  <a href="https://docs.python.org/3/library/urllib.request.html" rel="nofollow noreferrer">https://docs.python.org/3/library/urllib.request.html</a></p>
  <blockquote>
  <p>Request.method</p>
  <p>The HTTP request method to use. By default its value is None, which means that get_method() will do its normal computation of the method to be used. Its value can be set (thus overriding the default computation in get_method()) either by providing a default value by setting it at the class level in a Request subclass, or by passing a value in to the Request constructor via the method argument.</p>
  <p>New in version 3.3.</p>
  <p>Changed in version 3.4: A default value can now be set in subclasses; &gt;previously it could only be set via the constructor argument.</p>
  </blockquote>
  <p>&quot;method should be a string that indicates the HTTP request method that will be used (e.g. 'HEAD'). If provided, its value is stored in the method attribute and is used by get_method(). The default is 'GET' if data is None or 'POST' otherwise. Subclasses may indicate a different default method by setting the method attribute in the class itself.&quot;</p>