Skip to content

Commit 7e2d28a

Browse files
committed
Reordered exception handling while parsing response
2 parents 4bf8662 + 2c2a8b4 commit 7e2d28a

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The project provides an almost exhaustive access to the [Flickr API](https://www
1212
pip install flickr_api
1313
```
1414

15-
2. Aquire Flickr API keys and set up authorisation as per the [Wiki](https://github.com/alexis-mignon/python-flickr-api/wiki/Tutorial)
15+
2. Aquire Flickr API keys and set up authorisation as per the [Wiki](https://github.com/alexis-mignon/python-flickr-api/wiki/Flickr-API-Keys-and-Authentication)
1616

1717
3. Start using the OO interface!
1818

@@ -26,17 +26,19 @@ photos = user.getPhotos()
2626
If you've authorised yourself as a user, you can do cooler things like upload photos:
2727

2828
```python
29-
flickr_api.upload(photo_file = "path_to_the_photo_file", title = "My title")
29+
flickr_api.upload(photo_file="path_to_the_photo_file", title="My title")
3030
```
3131

3232
And even create albums (a.k.a Photosets):
3333

3434
```python
35-
photoset = flickr_api.Photoset.create(title = "The title of the photoset", primary_photo = cover_photo)
35+
photoset = flickr_api.Photoset.create(title="The title of the photoset", primary_photo=cover_photo)
3636
```
3737

3838
## Features
3939

40+
Consult the [API Reference](https://github.com/alexis-mignon/python-flickr-api/wiki/API-reference) for a (semi) complete list
41+
4042
* Object Oriented implementation
4143
* (Almost) comprehensive implementation
4244
* Uses OAuth for authentication
@@ -54,7 +56,12 @@ Please note that `flickrapi` on Pypi is a different distribution by a different
5456

5557
## API Guide
5658

57-
A brief guide is available in the [Wiki section](https://github.com/alexis-mignon/python-flickr-api/wiki/Tutorial).
59+
A brief guide is available in the [Wiki section](https://github.com/alexis-mignon/python-flickr-api/wiki/).
60+
61+
## Projects using this API
62+
> create a PR to add your project here!
63+
64+
* [FlickrBox](https://github.com/tomquirk/FlickrBox) - A Dropbox-like backup experience for your free 1TB Flickr library!
5865

5966
## Notes
6067

flickr_api/method_call.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,15 @@ def call_api(api_key=None, api_secret=None, auth_handler=None,
107107
query_elements = args.items()
108108
query_elements.sort()
109109
sig = keys.API_SECRET + \
110-
["".join(["".join(e) for e in query_elements])]
110+
["".join(["".join(e) for e in query_elements])]
111111
m = hashlib.md5()
112112
m.update(sig)
113113
api_sig = m.digest()
114114
args["api_sig"] = api_sig
115115
data = urllib.parse.urlencode(args)
116116
else:
117117
data = auth_handler.complete_parameters(
118-
url=request_url, params=args
118+
url=request_url, params=args
119119
).to_postdata()
120120

121121
if CACHE is None:
@@ -129,10 +129,13 @@ def call_api(api_key=None, api_secret=None, auth_handler=None,
129129
return resp
130130

131131
try:
132-
resp = json.loads(resp)
132+
try:
133+
resp = json.loads(resp.decode())
134+
except AttributeError:
135+
# exception for python 3 where `resp` is a string (doesn't need decoding)
136+
resp = json.loads(resp)
133137
except ValueError as e:
134138
logger.error("Could not parse response: %s", str(resp))
135-
raise e
136139

137140
if resp["stat"] != "ok":
138141
raise FlickrAPIError(resp["code"], resp["message"])

flickr_api/objects.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ def format_result(r, token=None):
777777
info = r["photosets"]
778778
photosets = info.pop("photoset")
779779
if not isinstance(photosets, list):
780-
phototsets = [photosets]
780+
photosets = [photosets]
781781
return FlickrList(
782782
[Photoset(token=token, **ps) for ps in photosets],
783783
Info(**info)
@@ -1303,7 +1303,7 @@ def save(self, filename, size_label=None):
13031303
given size.
13041304
13051305
Arguments:
1306-
filename: target file name
1306+
filename: target file name (without extension)
13071307
13081308
size_label: The label corresponding to the photo size
13091309
@@ -1317,8 +1317,12 @@ def save(self, filename, size_label=None):
13171317
"""
13181318
if size_label is None:
13191319
size_label = self._getLargestSizeLabel()
1320-
r = urllib.request.urlopen(self.getPhotoFile(size_label))
1321-
with open(filename, 'wb') as f:
1320+
1321+
photo_file = self.getPhotoFile(size_label)
1322+
file_ext = '.' + photo_file.split('.')[-1]
1323+
r = urllib.request.urlopen(photo_file)
1324+
1325+
with open(filename + file_ext, 'wb') as f:
13221326
f.write(r.read())
13231327
f.close()
13241328

0 commit comments

Comments
 (0)