Proof of quantization of magnetic charge of monopoles using homotopy groups Suppose we place a monopole at the origin $\{{\bf 0}\}$, and the gauge field is well-definded in region $\mathbb R^3-\{0\}$ which is homomorphic to a sphere $S^2$.
Then the total manifold is $U(1)$ fibers attached to base $S^2$. We may ask how many types of "phase texture" are there on a sphere? 
Then I use $\pi_2 (U(1)) = \pi_2(S^1)$ since we established the map $S^2\mapsto U(1) \sim S^1$.
But $\pi_2 (S^1) = 0$ not $\mathbb Z$! Where I got wrong?
According to the famous book Topology and Geometry for Physicists, the correct formula should be $$ \pi_1(S^1) = \mathbb Z.$$ Why $\pi_1$ instead of $\pi_2$?
 A: You want to specify how much "twist" there is in a $U(1)$ (i.e. effectively $S^1$) bundle over $S^2$.  If you cover $S^2$ with a North and South patch, then the transition region is topologically $S^1$ so the bundle is classified by maps $S^1$ to $U(1)$, i.e. you want $\pi_1(U(1))=\pi_1(S^1) = \mathbb{Z}$
A: What OP is classifying with $\pi_2 (G)$ [where the gauge group here is $G=U(1)$], is the globally$^1$ defined gauge transformations $g: M\to G$. This is typically not what we want to calculate.
When discussing the Dirac monopole physicists are instead interested in classifying inequivalent configurations of the dynamical variable of the theory, i.e. the gauge potential $A$. More precisely, in the Wu-Yang/bundle picture (which avoids the use of a Dirac string), we consider the associated vector bundle $$T^{*}M\otimes \mathfrak{g}~\to~ M,$$ where $\mathfrak{g}=\mathfrak{u}(1)$ is the corresponding Lie algebra. It is implicitly understood that the gauge potentials $A_{\alpha}: U_{\alpha}\to \mathfrak{g}$ are defined on local charts $U_{\alpha}\subset M$ with $\cup_{\alpha}U_{\alpha}=M$. Moreover it is implicitly understood that two local sections $A_{\alpha}: U_{\alpha}\to \mathfrak{g}$ and $A_{\beta}: U_{\beta}\to \mathfrak{g}$ are connected via local gauge transformations $g_{\alpha\beta}: U_{\alpha}\cap U_{\beta} \to G$ in the overlaps $U_{\alpha}\cap U_{\beta}$.
It turns out that we are therefore interested in counting maps from the equatorial overlap region $S^1$ to $G$, i.e. $\pi_1 (G)$, as twistor59 explains in his answer.
--
$^1$ The underlying space manifold for the Dirac monopole is $M=\mathbb{R}^3\backslash\{\bf 0\}$, which is homotopy equivalent (but not homeomorhic) to $S^2$. We have removed the origin, since the Dirac monopole is singular there. [The 't Hooft-Polyakov monopoles are regular in the full space $\mathbb{R}^3$, but we will not discuss these monopoles in this answer.]
