您params
没有使用Content-type
"multipart/form-data"
. 我尝试使用"application/x-www-form-urlencoded"
内容类型发送请求,它可以工作:
#!/usr/bin/env python
import re
import webbrowser
from netrc import netrc
from urllib import urlencode, quote
from urllib2 import urlopen
user, _, password = netrc().authenticators('spoj.com') # read from ~/.netrc
r = urlopen("https://www.spoj.com/submit/complete/", # no certificate test
data=urlencode(dict(
login_user=user,
password=password,
problemcode="TEST", # problem id
lang="116", # Python 3 (see languages below)
submit="Send",
file="for s in iter(input, '42'): print(s)")))
m = re.search(r'"newSubmissionId" value="(\d+)"/>', r.read()) # XXX dirty
print("submission id %d" % int(m.group(1)))
webbrowser.open("https://www.spoj.com/status/%s/" % quote(user))
语言
{
"7": "ADA 95 (gnat 4.3.2)",
"13": "Assembler (nasm 2.03.01)",
"104": "Awk (gawk-3.1.6)",
"28": "Bash (bash-4.0.37)",
"12": "Brainf**k (bff 1.0.3.1)",
"11": "C (gcc 4.3.2)",
"27": "C# (gmcs 2.0.1)",
"41": "C++ (g++ 4.3.2)",
"1": "C++ (g++ 4.0.0-8)",
"34": "C99 strict (gcc 4.3.2)",
"14": "Clips (clips 6.24)",
"111": "Clojure (clojure 1.1.0)",
"31": "Common Lisp (sbcl 1.0.18)",
"32": "Common Lisp (clisp 2.44.1)",
"20": "D (gdc 4.1.3)",
"36": "Erlang (erl 5.6.3)",
"124": "F# (fsharp 2.0.0)",
"5": "Fortran 95 (gfortran 4.3.2)",
"114": "Go (gc 2010-07-14)",
"21": "Haskell (ghc 6.10.4)",
"16": "Icon (iconc 9.4.3)",
"9": "Intercal (ick 0.28-4)",
"24": "JAR (JavaSE 6)",
"10": "Java (JavaSE 6)",
"35": "JavaScript (rhino 1.7R1-2)",
"26": "Lua (luac 5.1.3)",
"30": "Nemerle (ncc 0.9.3)",
"25": "Nice (nicec 0.9.6)",
"56": "Node.js (0.8.11)",
"8": "Ocaml (ocamlopt 3.10.2)",
"22": "Pascal (fpc 2.2.4)",
"2": "Pascal (gpc 20070904)",
"3": "Perl (perl 5.12.1)",
"54": "Perl 6 (rakudo-2010.08)",
"29": "PHP (php 5.2.6)",
"19": "Pike (pike 7.6.112)",
"15": "Prolog (swipl 5.6.58)",
"4": "Python (python 2.7)",
"116": "Python 3 (python 3.2.3)",
"126": "Python 3 nbc (python 3.2.3 nbc)",
"17": "Ruby (ruby 1.9.3)",
"39": "Scala (scala 2.8.0)",
"33": "Scheme (guile 1.8.5)",
"18": "Scheme (stalin 0.11)",
"46": "Sed (sed-4.2)",
"23": "Smalltalk (gst 3.0.3)",
"38": "Tcl (tclsh 8.5.3)",
"62": "Text (plain text)",
"6": "Whitespace (wspace 0.3)",
}