# How can I use \`sunpy.io.header\` to read a header from a URL?

**URL:** <https://community.openastronomy.org/t/how-can-i-use-sunpy-io-header-to-read-a-header-from-a-url/403>\
**Category:** SunPy\
**Tags:** sunpy, astropy, fits, question\
**Created:** [July 29, 2022, 5:57pm UTC](https://community.openastronomy.org/t/how-can-i-use-sunpy-io-header-to-read-a-header-from-a-url/403 "2022-07-29T17:57:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![azim](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@azim](https://community.openastronomy.org/u/azim)\
**Post date:** [July 29, 2022, 5:57pm UTC](https://community.openastronomy.org/t/how-can-i-use-sunpy-io-header-to-read-a-header-from-a-url/403/1 "2022-07-29T17:57:26Z")

</div>

I have URLs to header files, like this one:

“[https://gong2.nso.edu/HA/hah/201102/20110225/20110225175454Bh.hdr](https://gong2.nso.edu/HA/hah/201102/20110225/20110225175454Bh.hdr)”

Is there any of the astropy/sunpy modules that I can use to access such headers’ content without downloading + saving + loading + parsing the files?

Maybe [sunpy.io.header](https://docs.sunpy.org/en/stable/code_ref/io.html?highlight=header#module-sunpy.io.header), but I can’t find how to do that!

---

<div class="post-metadata">

**Author:** ![nabobalis](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/nabobalis/32/14_2.png) [@nabobalis](https://community.openastronomy.org/u/nabobalis)\
**Post date:** [August 8, 2022, 5:17pm UTC](https://community.openastronomy.org/t/how-can-i-use-sunpy-io-header-to-read-a-header-from-a-url/403/2 "2022-08-08T17:17:35Z")

</div>

Hi,

Sorry for the late reply (I forgot to enable tag notifications), from what I can see there is no easy way to do that.

Most of functions that are present in `sunpy.io` assume the file is local at the very least and while some functions handle URLS, they will error if the file isn’t a FITS file.

What you can do is this however:

```python
from astropy.io import fits
from astropy.utils.data import download_file

url = "https://gong2.nso.edu/HA/hah/201102/20110225/20110225175454Bh.hdr"
fits.Header.fromtextfile(download_file(url))

```

---

<div class="post-metadata">

**Author:** ![azim](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@azim](https://community.openastronomy.org/u/azim)\
**Post date:** [August 8, 2022, 5:35pm UTC](https://community.openastronomy.org/t/how-can-i-use-sunpy-io-header-to-read-a-header-from-a-url/403/3 "2022-08-08T17:35:51Z")

</div>

Thanks @nabobalis .  
This probably is the next best thing.
