diff --git a/flickr_api/upload.py b/flickr_api/upload.py
index 1595b7f..65de043 100644
--- a/flickr_api/upload.py
+++ b/flickr_api/upload.py
@@ -58,7 +58,7 @@ def post(url, auth_handler, args, photo_file, photo_file_data=None):
     data = resp.content
 
     if resp.status_code != 200:
-        raise FlickrError("HTTP Error %i: %s" % (r.status, data))
+        raise FlickrError("HTTP Error %i: %s" % (resp.status_code, resp.text))
 
     r = ET.fromstring(data)
     if r.get("stat") != 'ok':

Exception UnboundLocalError if server response not 200 when uploading photo
```
Traceback (most recent call last):
 
  File "/home/w/projects/panoedit/flickr_upload.py", line 60, in main
    path = os.path.join(conf.photos_dir, file_name)
  File "/home/w/projects/panoedit/google_venv/local/lib/python2.7/site-packages/flickr_api/upload.py", line 107, in upload
    r = post(UPLOAD_URL, auth.AUTH_HANDLER, args, photo_file, photo_file_data)
  File "/home/w/projects/panoedit/google_venv/local/lib/python2.7/site-packages/flickr_api/upload.py", line 61, in post
    raise FlickrError("HTTP Error %i: %s" % (r.status, data))
UnboundLocalError: local variable 'r' referenced before assignment
```
diff --git a/test/test_upload.py b/test/test_upload.py
new file mode 100644
index 0000000..90dffba
--- /dev/null
+++ b/test/test_upload.py
@@ -0,0 +1,37 @@
+import unittest
+from unittest.mock import MagicMock
+
+from flickr_api import upload
+from flickr_api.auth import AuthHandler
+from flickr_api.flickrerrors import FlickrError
+
+from requests import Response
+
+from io import StringIO
+from io import BytesIO
+
+import inspect
+
+class TestUpload(unittest.TestCase):
+    def test_upload_not_200(self):
+        from flickr_api import set_auth_handler
+        auth_handler = AuthHandler(key="test", secret="test", 
+            access_token_key="test",
+            access_token_secret="test")
+        set_auth_handler(auth_handler)
+        args = dict(
+            photo_file = '/tmp/test_file',
+            photo_file_data = StringIO("000000")
+        )
+
+        module = inspect.getmodule(upload)
+        resp = Response()
+        resp.status_code = 404
+        resp.raw = BytesIO("Not Found".encode("utf-8"))
+        module.requests.post = MagicMock(return_value=resp)
+
+        with self.assertRaises(FlickrError) as context:
+            upload(**args)
+        
+        print(context.exception)
+        self.assertEquals("HTTP Error 404: Not Found", str(context.exception))
\ No newline at end of file

pip install -e .
parse_log_pytest
requirements.txt
pytest
apt-get update apt-get install -y gcc
3.6
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs==22.2.0
certifi==2021.5.30
charset-normalizer==2.0.12
-e git+https://github.com/alexis-mignon/python-flickr-api.git@6d7e5f429ed252a77a0267ce3d248973f0f901b6#egg=flickr_api
httplib2==0.22.0
idna==3.10
importlib-metadata==4.8.3
iniconfig==1.1.1
oauth2==1.9.0.post1
packaging==21.3
pluggy==1.0.0
py==1.11.0
pyparsing==3.1.4
pytest==7.0.1
requests==2.27.1
six==1.17.0
tomli==1.2.3
typing_extensions==4.1.1
urllib3==1.26.20
zipp==3.6.0

name: python-flickr-api
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - attrs==22.2.0
      - charset-normalizer==2.0.12
      - httplib2==0.22.0
      - idna==3.10
      - importlib-metadata==4.8.3
      - iniconfig==1.1.1
      - oauth2==1.9.0.post1
      - packaging==21.3
      - pluggy==1.0.0
      - py==1.11.0
      - pyparsing==3.1.4
      - pytest==7.0.1
      - requests==2.27.1
      - six==1.17.0
      - tomli==1.2.3
      - typing-extensions==4.1.1
      - urllib3==1.26.20
      - zipp==3.6.0
prefix: /opt/conda/envs/python-flickr-api

test/test_upload.py::TestUpload::test_upload_not_200
flickr_api/upload.py
flickr_api/upload.py