Asked  7 Months ago    Answers:  5   Viewed   195 times

I am getting this error, when I am trying to call a box api through curl.

curl: (26) couldn't open file

Can't find why! I am calling this api with a correct file name-

curl https://upload.view-api.box.com/1/documents 
-H "Authorization: Token YOUR_API_TOKEN" 
-H "Content-type: multipart/form-data" 
-F file=@A_correct_file_name

I have seen all the three already asked questions but 2 of them are unanswered and one is specific to facebook.

cURL error 26 couldn't open file

Fatal error: Uncaught CurlException: 26: couldn't open file "" thrown in

Getting Fatal Error Uncaught CurlException: 26: couldn't open file

 Answers

77

Sorry guys! My bad. I had not included extension of the file in the file name. After including it, it worked. I am answering this in case someone does the same mistake in future.

Wednesday, March 31, 2021
 
Sujith
answered 7 Months ago
11

The "files" field only shows up on videos for PRO members who request their own videos. You must be authenticated as the owner of the video. If your goal is to play these videos, you should use OEmbed to request our embed iframe.

As for support, I am the Senior API Developer at Vimeo and personally handle the majority of API support cases. Can you please let me know where you previously posted your question? If it was in the forums, those are left over from a previous time and are not supported. We will soon move everyone to our Google Group.

All API support has moved to Email for private conversations, Google Groups for public conversations, and here on Stack Overflow for programming help.

Saturday, May 29, 2021
 
Lloydworth
answered 5 Months ago
61

The remote side sends the filename using the Content-Disposition header.

curl 7.21.2 or newer does this automatically if you specify --remote-header-name / -J.

curl -O -J -L $url
Tuesday, July 27, 2021
 
anjan
answered 3 Months ago
61
<?php
//
// A very simple PHP example that sends a HTTP POST to a remote site
//

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://xxxxxxxx.xxx/xx/xx");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
            "dispnumber=567567567&extension=6");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));


// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);

curl_close ($ch);

// further processing ....
if ($server_output == "OK") { ... } else { ... }

?>
Wednesday, July 28, 2021
 
jwegner
answered 3 Months ago
18

Simply pass open() a unicode string for the file name:

In Python 2.x:

>>> open(u'someUnicodeFilenameλ')
<open file u'someUnicodeFilenameu03bb', mode 'r' at 0x7f1b97e70780>

In Python 3.x, all strings are Unicode, so there is literally nothing to it.

As always, note that the best way to open a file is always using the with statement in conjunction with open().

Edit: With regards to os.listdir() the advice again varies, under Python 2.x, you have to be careful:

os.listdir(), which returns filenames, raises an issue: should it return the Unicode version of filenames, or should it return 8-bit strings containing the encoded versions? os.listdir() will do both, depending on whether you provided the directory path as an 8-bit string or a Unicode string. If you pass a Unicode string as the path, filenames will be decoded using the filesystem’s encoding and a list of Unicode strings will be returned, while passing an 8-bit path will return the 8-bit versions of the filenames.

Source

So in short, if you want Unicode out, put Unicode in:

>>> os.listdir(".")
['someUnicodeFilenamexcexbb', 'old', 'Dropbox', 'gdrb']
>>> os.listdir(u".")
[u'someUnicodeFilenameu03bb', u'old', u'Dropbox', u'gdrb']

Note that the file will still open either way - it won't be represented well within Python as it'll be an 8-bit string, but it'll still work.

open('someUnicodeFilenamexcexbb')
<open file 'someUnicodeFilenameλ', mode 'r' at 0x7f1b97e70660>

Under 3.x, as always, it's always Unicode.

Tuesday, August 3, 2021
 
ariel
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :