Integrating $\int _0^\pi \frac{1}{1+\sin^2(\theta)}$ using Cauchy's formula I need to evaluate $\displaystyle \int _0^\pi \frac{d\theta}{1+\sin^2(\theta)}$ by using Cauchy's integral formula, and the substitution $z = e^{i\theta}.$ So far, I have that 
$$d\theta = \frac{1}{iz}dz$$ and
$$1+\sin^2(\theta) = 1+ \frac{1}{4}\left(z^2 -2 +\frac{1}{z^2}\right) = \frac{1}{4}\left(4+ z^2 -2 +\frac{1}{z^2}\right) = \frac{1}{4}\left(2+ z^2 +\frac{1}{z^2}\right).$$

So the integral becomes

$$\int \frac{4dz}{iz \left(2+z^2+\frac{1}{z^2}\right)}= \int \frac{(4z)dz}{iz^4 +2iz^2+i}$$

Now, I'm not sure that last step was in the right direction, but it seems to me to be the only way I can factor the bottom so that I can apply Cauchy's integral formula. Now, the bottom factors as 
$$(z-i)^2(z+i)(iz-i).$$
However, I'm a bit confused about this factorization because I did it by polynomial division. But when I used the quadratic formula, I got that $z = -i$ is also a double root, which would imply that it factorizes as $$(z-i)^2(z+i)^2.$$ So first of all, can someone help me clear up this confusion? And second, I'm not quite sure where to be evaluating the integral because both of the singularities lie on the unit circle, and I am only supposed to integrate from $0$ to $\pi,$ so should I just take half of the integral from $0$ to $2\pi$? If this is not always possible, I'd appreciate a brief explanation as to why.
One way to consider is to write:

$\displaystyle \int_{0}^{\pi}\frac{1}{1+\frac{1-\cos(2x)}{2}}dx$

$\displaystyle=\int_{0}^{\pi}\frac{2}{3-\cos(2x)}dx$

Let $t=2x, \;\ dx=1/2dt$

$\displaystyle\int_{0}^{2\pi}\frac{1}{3-\cos(t)}dt$

Now, use the complex cos rep.

$\displaystyle\int_{C} \frac{1}{3-\frac{z+z^{-1}}{2}}\cdot \frac{1}{zi}dz$

$\displaystyle\int_{C} \frac{2i}{z^{2}-6z+1}dz$

Only the pole $-2\sqrt{2}+3$ lies in the unit circle.

$\displaystyle 2\pi i Res(-2\sqrt{2}+3)=2\pi i \left(\frac{-i}{2\sqrt{2}}\right)=\frac{\pi}{\sqrt{2}}$
With $\sin \theta = \dfrac{z - 1/z}{2i}$ you should get $$1 + \sin^2 \theta = - \dfrac{z^2}{4} + \dfrac{3}{2} - \dfrac{1}{4z^2} $$
You certainly shouldn't have singularities on the unit circle since $1+\sin^2 \theta$ is never $0$ for real $\theta$.  

You'll want to integrate over the whole circle to use the Residue Theorem, so 
yes, take half of the integral from $0$ to $2 \pi$.