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

Invalid requirement: '\x00' #442

Open
dan-danciu opened this issue Dec 19, 2019 · 8 comments
Open

Invalid requirement: '\x00' #442

dan-danciu opened this issue Dec 19, 2019 · 8 comments

Comments

@dan-danciu
Copy link

dan-danciu commented Dec 19, 2019

I ended up following this this to the letter on two different PCs:
https://serverless.com/blog/serverless-python-packaging/

But I still get the same error everywhere:


  Error --------------------------------------------------                                                                            
                                                                                                                                      
  Error: STDOUT:                                                                                                                      
                                                                                                                                      
  STDERR: ERROR: Invalid requirement: '\x00' (from line 1 of /var/task/requirements.txt)                                              
                                                                                                                                 
      at D:\git\numpy-test\node_modules\serverless-python-requirements\lib\pip.js:320:13                                              
      at Array.forEach (<anonymous>)                                                                                                  
      at installRequirements (D:\git\numpy-test\node_modules\serverless-python- 
 requirements\lib\pip.js:307:28)                        
      at installRequirementsIfNeeded (D:\git\numpy-test\node_modules\serverless-python- 
 requirements\lib\pip.js:551:3)                 
      at ServerlessPythonRequirements.installAllRequirements (D:\git\numpy- 
 test\node_modules\serverless-python-requirements\lib\pip.js
  :630:29)                                                                                                                              
      at ServerlessPythonRequirements.tryCatcher (D:\git\numpy- 
 test\node_modules\bluebird\js\release\util.js:16:23)                   
      at Promise._settlePromiseFromHandler (D:\git\numpy- 
 test\node_modules\bluebird\js\release\promise.js:547:31)                     
      at Promise._settlePromise (D:\git\numpy- 
 test\node_modules\bluebird\js\release\promise.js:604:18)                                
      at Promise._settlePromise0 (D:\git\numpy- 
 test\node_modules\bluebird\js\release\promise.js:649:10)                               
      at Promise._settlePromises (D:\git\numpy- 
 test\node_modules\bluebird\js\release\promise.js:729:18)                               
      at _drainQueueStep (D:\git\numpy-test\node_modules\bluebird\js\release\async.js:93:12)                                          
      at _drainQueue (D:\git\numpy-test\node_modules\bluebird\js\release\async.js:86:9)                                               
      at Async._drainQueues (D:\git\numpy-test\node_modules\bluebird\js\release\async.js:102:5)                                       
      at Immediate.Async.drainQueues [as _onImmediate] (D:\git\numpy- 
 test\node_modules\bluebird\js\release\async.js:15:14)            
      at processImmediate (internal/timers.js:439:21)                                                                                 
      at process.topLevelDomainCallback (domain.js:131:23)                                                                            
                                                                                                                                      
     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.                                              

The requirements.txt is absolutely fine in my project root folder but when I look at it in the .serverless folder it looks completely messed up:

root:
image

.serverless:
image

I can not replace it as the plugin copies it every time serverless tries to package the thing so what am I doing wrong?

@devFranz
Copy link

I have the same issue. I ended up installing the modules in the root folder (not neat solution but it worked at the end).

@mpalmerjac
Copy link

I solved this problem by saving the contents of requirements.txt as ascii, not unicode. Worked fine after that.

@hariprasad0511
Copy link

I solved this problem by saving the contents of requirements.txt as ascii, not unicode. Worked fine after that.

Worked for me too.

Although I would like o understand why and if serverless itself can't handle this conversion.

@n-wagner
Copy link

n-wagner commented May 4, 2021

The above helped fix the problem for me too, but I think I may have figured out what the underlying issue is here.

If you're running pip freeze > requirements.txt on PowerShell you have to be careful what version of PowerShell you're on. The > operator is a shortcut to Out-File and the default encoding parameter for it in Powershell 5.1 at least is Unicode which is UTF-16LE as per this specification.

Default value: Unicode

Moreover, it looks like even though this is corrected in the current latest release for PowerShell, the > operator may still output the UTF-16LE format as per this specification for PowerShell 7.1.

Default value: UTF8NoBOM

and

Out-File and the redirection operators > and >> create UTF-16LE, which notably differs from Set-Content and Add-Content.

respectively.

This doesn't appear to be an issue with this plugin, the way to fix it definitively is to execute:

pip freeze | Out-File -Encoding UTF8 requirements.txt

when generating requirements files on PowerShell or use the original redirection method on Command Prompt.

@f00f
Copy link

f00f commented Jul 29, 2021

Converting the requirements.txt to UTF8 fixed the issue for me. Thanks for the updated PoSH command, @n-wagner.

However, I wonder where this goes wrong? python -m pip install -r .\requirements.txt works for me even with a UTF16LE file.
Would be nice for noobs (like me) if this were fixed.

@n-wagner
Copy link

n-wagner commented Jul 29, 2021

@f00f i haven’t touched this in a while but if I recall correctly that isn’t the issue. It’s that the serverless plug-in rewrites the file to another directory and it assumes a UTF8 encoding when it opens it. The failure happens when it attempts to read the UTF16LE file like a UTF8 and then dump it to another requirements.txt file. So pip install may work fine but the rewrite portion of the plug-in is more brittle. This is to guard against that. Hope that helps!

@ebartan
Copy link

ebartan commented Oct 11, 2021

pip freeze | Out-File -Encoding UTF8 requirements.txt it's work it for me

The above helped fix the problem for me too, but I think I may have figured out what the underlying issue is here.

If you're running pip freeze > requirements.txt on PowerShell you have to be careful what version of PowerShell you're on. The > operator is a shortcut to Out-File and the default encoding parameter for it in Powershell 5.1 at least is Unicode which is UTF-16LE as per this specification.

Default value: Unicode

Moreover, it looks like even though this is corrected in the current latest release for PowerShell, the > operator may still output the UTF-16LE format as per this specification for PowerShell 7.1.

Default value: UTF8NoBOM

and

Out-File and the redirection operators > and >> create UTF-16LE, which notably differs from Set-Content and Add-Content.

respectively.

This doesn't appear to be an issue with this plugin, the way to fix it definitively is to execute:

pip freeze | Out-File -Encoding UTF8 requirements.txt

when generating requirements files on PowerShell or use the original redirection method on Command Prompt.

@f00f
Copy link

f00f commented Aug 3, 2022

@pgrzesik: Would a "fix" be to check the file encoding before opening it as utf8, and if it's a different encoding, issue an error and exit?
(note: the offending file read is probably in function generateRequirementsFile in the file lib/pip.js)

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

No branches or pull requests

8 participants