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

Can't upload attachments with .save in .new #25

Closed
wick2o opened this issue Mar 31, 2014 · 8 comments
Closed

Can't upload attachments with .save in .new #25

wick2o opened this issue Mar 31, 2014 · 8 comments
Assignees
Labels

Comments

@wick2o
Copy link

wick2o commented Mar 31, 2014

This happens when the following code is run
issue.requireditems_here

issue.uploads = [{'path': '/folder/folderDocuments/sample_37c8b57c0811b74f44c4ee0ae300b608.zip'}]
issue.save

This happens both with and without the patch

Traceback (most recent call last):
File "./kedmine.py", line 137, in
main()
File "./kedmine.py", line 125, in main
res = issue.save()
File "/Library/Python/2.7/site-packages/python_redmine-0.8.0-py2.7.egg/redmine/resources.py", line 227, in save
for item, value in self.manager.create(**self._changes):
File "/Library/Python/2.7/site-packages/python_redmine-0.8.0-py2.7.egg/redmine/managers.py", line 164, in create
fields['uploads'][index]['token'] = self.redmine.upload(upload.get('path', ''))
File "/Library/Python/2.7/site-packages/python_redmine-0.8.0-py2.7.egg/redmine/init.py", line 49, in upload
print response['upload']['token']
TypeError: 'NoneType' object has no attribute 'getitem'

@maxtepkeev
Copy link
Owner

Can't reproduce this error, everything works perfectly for me, here's the code:

>>> issue = redmine.issue.new()
>>> issue.project_id = 'some_project'
>>> issue.subject = 'test'
>>> issue.uploads = [{'path': '/some/path/to/file/test.zip'}]
>>> issue.save()
True

Also, you error message is a little bit strange, why do you have this print response['upload']['token'] in File "/Library/Python/2.7/site-packages/python_redmine-0.8.0-py2.7.egg/redmine/__init_.py", line 49.
There is no such code in the package, looks like you've added it yourself while debugging. Please try uninstalling python-redmine and then reinstalling it again. Also please try installing the previous python-redmine version (0.7.2) and see if it works for you because I changed some code for file uploads in the latest version.

If the error is still there I need more details from you to reproduce this:

  • Your exact code which causes the error
  • Your Python version
  • Your Redmine version

@maxtepkeev maxtepkeev self-assigned this Mar 31, 2014
@wick2o
Copy link
Author

wick2o commented Mar 31, 2014

I removed the version i had (and yes, i was trying to trouble shoot the issue myself). I now have a freash copy from easy_install (0.8.0). I reran my code and got my original error which is:

Traceback (most recent call last):
File "./kedmine.py", line 137, in
main()
File "./kedmine.py", line 125, in main
res = issue.save()
File "/Library/Python/2.7/site-packages/python_redmine-0.8.0-py2.7.egg/redmine/resources.py", line 227, in save
for item, value in self.manager.create(**self._changes):
File "/Library/Python/2.7/site-packages/python_redmine-0.8.0-py2.7.egg/redmine/managers.py", line 158, in create
fields['uploads'][index]['token'] = self.redmine.upload(upload.get('path', ''))
File "/Library/Python/2.7/site-packages/python_redmine-0.8.0-py2.7.egg/redmine/init.py", line 50, in upload
return response['upload']['token']
TypeError: 'NoneType' object has no attribute 'getitem'

I am running python 2.7.5 and my code is as follows (some items renamed to protect the innocent). It shouldn't matter, but I am coding on mac OSX 10

issue = redmine.issue.new()
issue.project_id = 'XXXX'
issue.assigned_to_id = m_id
issue.watcher_user_ids = [62, 10]
issue.subject = args.subject
issue.description = args.description
issue.status_id = 1
issue.priority_id = 2
issue.tracker_id = 15
issue.uploads = [{'path': '/hard/coded/path/for/testing.zip'}]
res = issue.save()

@maxtepkeev
Copy link
Owner

OK, it seems that the response returned None, that means that something is wrong. You didn't tell me what Redmine version do you use. Also please show me the print of the response.status_code and response.content from response variable which is in

/Library/Python/2.7/site-packages/python_redmine-0.8.0-py2.7.egg/redmine/__init_.py

in line 77 (response = getattr(requests, method)(url, **kwargs))

@wick2o
Copy link
Author

wick2o commented Mar 31, 2014

Max,

Sorry, im using the 0.8.0 that gets installed when you do an easy_install.

it seems that the json is too large looking at the below error. Which is
weird because the file is only 360KB and uploads fine manually. A work
around might be for me to create a ticket with .save and then upload it
with my file, but that seems unneeded.


200
{"user":{"custom_fields":[{"value":"pastels_on_dark","name":"Ultraviolet
Theme","id":12}],"created_on":"2014/03/10 13:03:51
-0700","lastname":"LAST","mail":"ME@DOMAIN","firstname":"Jaime","id":XX,"last_login_on":"2014/03/31
09:25:17 -0700"}}



413

<title>413 Request Entity Too Large</title>

Request Entity Too Large

The requested resource
/uploads.json

does not allow request data with POST requests, or the amount of data
provided in
the request exceeds the capacity limit.


Apache/2.2.15 (CentOS) Server at project.DOMAIN.com Port 443

On Mon, Mar 31, 2014 at 11:44 AM, Max Tepkeev notifications@github.comwrote:

OK, it seems that the response returned None, that means that something
is wrong. You didn't tell me what Redmine version do you use. Also please
show me the print of the response.status_code and response.content from
response variable which is in

/Library/Python/2.7/site-packages/python_redmine-0.8.0-py2.7.egg/redmine/_init.py

in line 77 (response = getattr(requests, method)(url, **kwargs))

Reply to this email directly or view it on GitHubhttps://github.com//issues/25#issuecomment-39104057
.

@maxtepkeev
Copy link
Owner

Hi!

0.8.0 is the version of Python Redmine, and not the Redmine itself. I was asking your Redmine version because your problem is not related to Python Redmine but either to the Redmine itself or to the web server hosting your Redmine application (seems to be Apache in your case).

Keep in mind that file uploads via REST API are available only for Redmine 1.4.0+

Also, there is a LimitRequestBody directive in Apache which controls this limits. If you have nginx in front of Apache there is a client_max_body_size directive which also controls the request body limits.

I'm afraid that's all I can do for you because the problem doesn't seem to be related with Python Redmine. You have to upgrade your Redmine if it's < 1.4.0 and play with Redmine/Apache/Nginx settings to make uploads work.

I'm not closing this issue in case you'll have any more questions about this problem. Also if you'll find a solution please post it here for others. Thanks.

@wick2o
Copy link
Author

wick2o commented Apr 1, 2014

It appears to be the Redmine version. I'm just going to write some code to
upload the file via a POST outside of the API. Might a suggest a version
check, or handling the error so it doesn't just crash?

On Tue, Apr 1, 2014 at 3:46 AM, Max Tepkeev notifications@github.comwrote:

Hi!

0.8.0 is the version of Python Redmine, and not the Redmine itself. I was
asking your Redmine version because your problem is not related to Python
Redmine but either to the Redmine itself or to the web server hosting your
Redmine application (seems to be Apache in your case).

Keep in mind that file uploads via REST API are available only for Redmine
1.4.0+

Also, there is a LimitRequestBodyhttp://httpd.apache.org/docs/2.2/mod/core.html#limitrequestbodydirective in Apache which controls this limits. If you have nginx in front
of Apache there is a client_max_body_sizehttp://wiki.nginx.org/HttpCoreModule#client_max_body_sizedirective which also controls the request body limits.

I'm afraid that's all I can do for you because the problem doesn't seem to
be related with Python Redmine. You have to upgrade your Redmine if it's <
1.4.0 and play with Redmine/Apache/Nginx settings to make uploads work.

I'm not closing this issue in case you'll have any more questions about
this problem. Also if you'll find a solution please post it here for
others. Thanks.

Reply to this email directly or view it on GitHubhttps://github.com//issues/25#issuecomment-39178748
.

@maxtepkeev
Copy link
Owner

0.8.0 can't be the Redmine version, because REST API become available only from Redmine 1.0+. You can find your Redmine version at http://your-redmine-url/admin/info

There is a version check in Python Redmine but you have to specify your Redmine version explicitly in

redmine = Redmine('http://demo.redmine.org', version='2.3.3')

because there is currently no way to get the Redmine version through it's api.

@maxtepkeev
Copy link
Owner

I added additional error checks which are available as of v0.8.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants