How to send POST request?

If you really want to handle with HTTP using Python, I highly recommend Requests: HTTP for Humans. The POST quickstart adapted to your question is: >>> import requests >>> r = requests.post(“http://bugs.python.org”, data={‘number’: 12524, ‘type’: ‘issue’, ‘action’: ‘show’}) >>> print(r.status_code, r.reason) 200 OK >>> print(r.text[:300] + ‘…’) <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”> … Read more

No module named MySQLdb

You need to use one of the following commands. Which one depends on what OS and software you have and use. easy_install mysql-python (mix os) pip install mysql-python (mix os/ python 2) pip install mysqlclient (mix os/ python 3) apt-get install python-mysqldb (Linux Ubuntu, …) cd /usr/ports/databases/py-MySQLdb && make install clean (FreeBSD) yum install MySQL-python … Read more

How to use XPath in Python?

libxml2 has a number of advantages: Compliance to the spec Active development and a community participation Speed. This is really a python wrapper around a C implementation. Ubiquity. The libxml2 library is pervasive and thus well tested. Downsides include: Compliance to the spec. It’s strict. Things like default namespace handling are easier in other libraries. … Read more

Nested arguments not compiling

PEP 3113 explains why this feature, “tuple parameter unpacking”, was removed in Python 3. It also explains how to port code that uses them. In this case you’d need to change a function like: def add(self, (sub, pred, obj)): self._addToIndex(self._spo, sub, pred, obj) self._addToIndex(self._pos, pred, obj, sub) self._addToIndex(self._osp, obj, sub, pred) to a version which … Read more

What are the differences between the urllib, urllib2, urllib3 and requests module?

I know it’s been said already, but I’d highly recommend the requests Python package. If you’ve used languages other than python, you’re probably thinking urllib and urllib2 are easy to use, not much code, and highly capable, that’s how I used to think. But the requests package is so unbelievably useful and short that everyone … Read more