Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: decode() argument 1 must be string, not None #14

Closed
Linuturk opened this issue Feb 12, 2013 · 7 comments
Closed

TypeError: decode() argument 1 must be string, not None #14

Linuturk opened this issue Feb 12, 2013 · 7 comments

Comments

@Linuturk
Copy link

The new sync_folder_to_container looks awesome, but I'm getting a type error when I attempt to call it.

My script: https://github.com/Linuturk/www.onitato.com/blob/master/cf_pyrax.py

Output after the various credentials are supplied at the top of the file.

Syncing all objects to www.onitato.com container from folder /var/lib/jenkins/workspace/www.onitato.com/output/.
Traceback (most recent call last):
  File "cf_pyrax.py", line 25, in <module>
    upload_key, total_bytes = cf_ord.sync_folder_to_container(folder, container, delete=True, include_hidden=True, ignore_timestamps=True)
  File "/usr/lib/python2.6/site-packages/pyrax/cf_wrapper/client.py", line 516, in sync_folder_to_container
    include_hidden=include_hidden, ignore_timestamps=ignore_timestamps)
  File "/usr/lib/python2.6/site-packages/pyrax/cf_wrapper/client.py", line 534, in _sync_folder_to_container
    include_hidden=include_hidden, ignore_timestamps=ignore_timestamps)
  File "/usr/lib/python2.6/site-packages/pyrax/cf_wrapper/client.py", line 542, in _sync_folder_to_container
    obj = cont.get_object(fullname)
  File "/usr/lib/python2.6/site-packages/pyrax/cf_wrapper/container.py", line 85, in get_object
    name = name.decode(pyrax.encoding)
TypeError: decode() argument 1 must be string, not None
@dustinfarris
Copy link

I got this error, too. I solved by setting encoding to UTF-8.

pyrax.encoding = "utf-8"

According to the documentation, the encoding is supposed to be UTF-8 by default. I think this is a bug.

@EdLeafe
Copy link
Contributor

EdLeafe commented Feb 12, 2013

There is an error in line 25 of your script:

 upload_key, total_bytes = cf_ord.sync_folder_to_container(folder, container, delete=True, include_hidden=True, ignore_timestamps=True)

You are using the method signature for cf.upload_folder(); cf.sync_folder_to_container() doesn't run in the background.

That doesn't explain the encoding issue, though. Make sure that you don't have an encoding = entry in your .pyrax.cfg file, and then in your script, add this line right after you import pyrax:

print "Encoding:", pyrax.encoding

That should print 'utf-8', which is the default.

@Linuturk
Copy link
Author

No pyrax.cfg in use.

Updated the code: https://github.com/Linuturk/www.onitato.com/blob/master/cf_pyrax.py

Updated Output:

Encoding: None
Syncing all objects to www.onitato.com container from folder /var/lib/jenkins/workspace/www.onitato.com/output/.
Sync complete.

@dustinfarris
Copy link

@EdLeafe I, too, have experienced this error without using a configuration file at all:

>>> import pyrax
>>> pyrax.set_credentials('dustinfarris', 'xxxapikeyxxx')
>>> connection = pyrax.connect_to_couldfiles(region="ORD")
>>> container = connection.get_container("dustinfarris")
>>> connection.sync_folder_to_container("/Users/dustin/Documents/", container)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/dustin/.virtualenvs/dustinfarris/lib/python2.7/site-packages/pyrax/cf_wrapper/client.py", line 516, in sync_folder_to_container
    include_hidden=include_hidden, ignore_timestamps=ignore_timestamps)
  File "/Users/dustin/.virtualenvs/dustinfarris/lib/python2.7/site-packages/pyrax/cf_wrapper/client.py", line 542, in _sync_folder_to_container
    obj = cont.get_object(fullname)
  File "/Users/dustin/.virtualenvs/dustinfarris/lib/python2.7/site-packages/pyrax/cf_wrapper/container.py", line 85, in get_object
    name = name.decode(pyrax.encoding)
TypeError: decode() argument 1 must be string, not None
>>>

As I mentioned above, explicitly setting pyrax.encoding to "utf-8" resolves the error.

This was referenced Feb 12, 2013
@simonklee
Copy link
Contributor

@EdLeafe Unless _read_config_settings is actually called, encoding is set to None. You never actually set this variable anywhere else than in the mentioned function.

@EdLeafe
Copy link
Contributor

EdLeafe commented Feb 15, 2013

Ah, I see it now - thanks. I will have this fixed soon, and will include the fix to issue #10, too.

@EdLeafe
Copy link
Contributor

EdLeafe commented Feb 17, 2013

Please test with the current 'working' branch and let me know if you still see any issues.

EdLeafe added a commit that referenced this issue Feb 18, 2013
Also fixed an issue with multiple logger handlers being assigned to each client.
@EdLeafe EdLeafe closed this as completed Mar 4, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants