Considering that light is affected by gravity, how accurate are measurements of distant stars and galaxies? When light passes through objects with great mass, such as Jupiter size planets, stars, or black holes, shouldn't it change its course and result in a deviation of trajectory? Does the light we see with telescopes when observing the many celestial bodies in the sky pinpoint the real location of such bodies in the past, or was its past location divergent from the point in space indicated by the light reaching us today?
Large masses can bend light, but space is largely empty. The light from distant stars and galaxies rarely passes close enough to another star or galaxy to have deviated. On the few occasions when it does, it is special and notable.
For example, the Einstein cross looks like four quasars in a (very small) square, with a galaxy in front of it. In fact it is four images of one quasar, the light having been bent by the gravity of the foreground galaxy. In this case the image of the quasar is split up and moved by a few thousanths of a degree, because there is a very exact alignment of a quasar and a galaxy.
Such examples are rare. For nearly everything else the light has travelled in a straight line through flat and empty space. The light we see pinpoints the location that the object was when the light was emitted.
An exception to this is that our own sun (and to a lesser extent the other planets) create local distortions. In very high accuracy measurements this can be taken into account. But the distortions are very small and as we know the location of the sun, they can be fully taken into account.
Although the light travels in straight lines, it can be very hard to measure the distance to stars and galaxies. Often there is considerable uncertainty on the distance of astronomical objects. But this is not a result of gravity, it is just because measuring distance is hard.
The answer by James K is probably what you want to know, but your question does touch on general relativity (the gravitational bending of light is a general-relativistic effect), so here is a little more on that aspect of it.
Your question sort of assumes that light normally travels in straight lines, that it's obvious what "straight" means, and that it always makes sense to ask what is the state of some distant portion of the universe "now." Really the definition of "straight" and "now" become pretty subtle, or even completely undefined in general relativity (GR).
In GR, we define the trajectory of a test particle through spacetime to be straight. This is called a geodesic. So a photon by definition travels "straight." However, spacetime itself is curved, so the geometry of straight lines is noneuclidean. In GR, gravity is the curvature of spacetime. For example, you can have two rays of light emitted by the same star in two different direction, and because of the gravity of some intervening object, those rays can collide later. So this is a geometry in which straight lines can intersect in more than one place.
The path of the earth through spacetime is "straight" according to GR, even though by Newtonian standards it seems like it should be curved.
GR also doesn't have a universal notion of "now." So if we ask, "how far away is that distant galaxy," implying "how far is it right now," there is no totally well-defined answer. The space between us and it is expanding all the time. Because cosmological models are fairly uniform, we can get away with the following workaround in the example of the distant galaxy. We define time as the time on a clock that started at the big bang, and then was at rest relative to the nearby matter since then.
This answer is meant to supplement the existing answers with a bit more detail about the accuracies of our position and distance estimates for celestial bodies.
We know the positions of many bodies on the celestial sphere with great accuracy. The VLBI interferometer allows for angular resolution on the order of tens of micro-arcseconds. This is equivalent to being able to "read a newspaper in Singapore from a sidewalk café in Tokyo". As a comparison, the human eye is capable of resolution on the order of an arcminute. The angular resolution of an interferometer radio telescope is a function of the distance between the elements (along with the wavelength of the signal), and the VLBI elements were chosen to give a maximum distance between elements.
Our distance estimates and resolution are not nearly as accurate. We disagree about the distances of even relatively close stars like the Pleiades. Melis et al. (2014) describe this in A VLBI Resolution of the Pleiades Distance Controversy:
the cluster distance of 120.2+/-1.5 pc as measured by the optical space astrometry mission Hipparcos is significantly different from the distance of 133.5+/-1.2 pc derived with other techniques. We present an absolute trigonometric parallax distance measurement to the Pleiades cluster that uses very long baseline radio interferometry. This distance of 136.2+/-1.2 pc is the most accurate and precise yet presented for the cluster and is incompatible with the Hipparcos distance determination. Our results cement existing astrophysical models for Pleiades-age stars.
So, even without the rare gravitational bending of light, accurate distance measures are quite difficult and usually model dependent.